htaccess的重写规则和的DirectoryIndex

编程入门 行业动态 更新时间:2024-10-24 16:29:24
本文介绍了htaccess的重写规则和的DirectoryIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有我的重写规则和目录索引的问题

的DirectoryIndex invite.php about.php account.php 重写规则^ /?([A-Z0-9 _-] +)/ $ /user.php?u=$1 [L]

比方说 about.php 是在有关文件夹。当我去www.url/about/about.php~~V,它工作正常。但是,当我去 www.url/about / ,它进入我的 user.php的页。当我去 www.url/about ,(没有结束斜线),它进入 www.url /约/?U =约

谁能帮我?

与此同时,我试图设置,而不是 WWW保存用户可以去 www.url/andrewliu 。 url/user.php?u=andrewliu

我想我需要以某种方式解决我的结局斜杠和重定向?

谢谢!

修改

我有这样的

的DirectoryIndex invite.php about.php account.php RewriteEngine叙述上 的RewriteCond%{} REQUEST_FILENAME!-d 的RewriteCond%{REQUEST_FILENAME} \ PHP -f 重写规则^(。*)$ $ 1.PHP 重写规则^ /?([A-Z0-9 _-] +)/ $ /user.php?u=$1 [L] 的RewriteCond%{QUERY_STRING}!^ B = [NC] 重写规则^(业务)/(。*)$ /$1/index.php?b=$2 [L,NC,QSA]

解决方案

您需要添加一个检查,看看该请求是否是一个存在的文件或目录。您需要将您的规则之前添加以下条件:

的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重写规则^ /?([A-Z0-9 _-] +)/ $ /user.php?u=$1 [L]

这使得它,所以当你去 /约/ ,因为它是一个真实存在的目录,此规则将不适用。但是,如果你去 / andrewliu ,这将是只要这不是一个文件或目录。

I'm having issues with my rewriterule and directory index

DirectoryIndex invite.php about.php account.php RewriteRule ^/?([a-z0-9_-]+)/?$ /user.php?u=$1 [L]

Lets say about.php is in the about folder. When i go to www.url/about/about.php, it works fine. But when I go to www.url/about/, it goes to my user.php page. When I go to www.url/about, (without ending slash), it goes to www.url/about/?u=about

Can anyone help me?

At the same time, I'm trying to set up where user can go to www.url/andrewliu instead of www.url/user.php?u=andrewliu

I guess I need to somehow fix my ending slash and the redirect?

Thanks!

EDIT

I have this

DirectoryIndex invite.php about.php account.php RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^/?([a-z0-9_-]+)/?$ /user.php?u=$1 [L] RewriteCond %{QUERY_STRING} !^b= [NC] RewriteRule ^(business)/(.*)$ /$1/index.php?b=$2 [L,NC,QSA]

解决方案

You need to add a check to see whether the request is for a file or directory that exists. You need to add these conditions before your rule:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([a-z0-9_-]+)/?$ /user.php?u=$1 [L]

This makes it so when you go to /about/, since it's a directory that exists, this rule won't be applied. But if you go to /andrewliu, it will be as long as that's not a file or directory.

更多推荐

htaccess的重写规则和的DirectoryIndex

本文发布于:2023-11-01 20:00:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   规则   htaccess   DirectoryIndex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!