Php .htaccess错误读取目录

Php .htaccess错误读取目录,php,apache,.htaccess,clean-urls,Php,Apache,.htaccess,Clean Urls,我有一个为索引页设置变量的设置,但它也为目录设置了相同的变量,我不希望它这样做。这是我的.htaccess文件: RewriteEngine On RewriteCond %{REQUEST_URI} !^/(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js) [NC] RewriteRule ^(

我有一个为索引页设置变量的设置,但它也为目录设置了相同的变量,我不希望它这样做。这是我的.htaccess文件:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js) [NC]

RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z]+)/$ index.php?name=$1

RewriteRule ^([a-zA-Z]+)/([a-zA-Z0-9_]+)$ index.php?name=$1&page=$2
RewriteRule ^([a-zA-Z]+)/([a-zA-Z0-9_]+)/$ index.php?name=$1&page=$2

RewriteRule ^php/$ error/
现在,在这个设置中,如果我输入
mysite.com/login
,它将重定向到
index.php
页面,并将
login
设置为
name
变量。我如何使它到达忽略目录的位置?这让我很沮丧,我已经在这个网站上搜索了一个多小时的答案,却找不到一个类似的问题(不过我可能也很烂,哈哈!)

另外,如果查看上一个
重写规则
,您会发现我正在尝试将任何访问
php/
文件夹的尝试重定向到我的
error/
文件夹。这也不起作用

RewriteCond %{REQUEST_URI} !^/(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js) [NC] !-d


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
不在目录或文件上执行规则

有关文档页面的更多信息,请搜索
CondPattern

不在目录或文件上执行规则


有关文档页面的更多信息,请搜索
CondPattern

RewriteCond
仅适用于紧跟其后的
重写规则。另外,通过在末尾使用
/?
可以分别组合第3行和第4行以及第5行和第6行,这使得
/
是可选的()

您的文件可能与此类似:

RewriteEngine On
#the following line will not rewrite to anything because of "-", & stop rewiting with [L]
RewriteRule ^(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js)/?(.*)$ - [L,NC]
RewriteRule ^php/?(.*)$ error/ [L,NC]
RewriteRule ^([^/]+)/?$ index.php?name=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?name=$1&page=$2 [L]

您可能对.

RewriteCond
感兴趣,它只适用于紧跟其后的
重写规则。另外,通过在末尾使用
/?
可以分别组合第3行和第4行以及第5行和第6行,这使得
/
是可选的()

您的文件可能与此类似:

RewriteEngine On
#the following line will not rewrite to anything because of "-", & stop rewiting with [L]
RewriteRule ^(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js)/?(.*)$ - [L,NC]
RewriteRule ^php/?(.*)$ error/ [L,NC]
RewriteRule ^([^/]+)/?$ index.php?name=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?name=$1&page=$2 [L]

您可能会对这个问题感兴趣。

这很有效!谢谢但是,最下面的两个
RewriteRule
s不起作用。我不得不将
[^/]
更改为
[a-zA-Z0-9]
。现在一切都好了。谢谢好吧,这很奇怪。除非您只需要字母和数字,[^/]匹配除/之外的所有内容,那么它是拒绝重定向,还是不是您的预期行为?我刚才还加了/?到最底层的正则表达式,因为我不知怎的把它忘了。(抱歉,某些移动设备没有波浪键!)这很有效!谢谢但是,最下面的两个
RewriteRule
s不起作用。我不得不将
[^/]
更改为
[a-zA-Z0-9]
。现在一切都好了。谢谢好吧,这很奇怪。除非您只需要字母和数字,[^/]匹配除/之外的所有内容,那么它是拒绝重定向,还是不是您的预期行为?我刚才还加了/?到最底层的正则表达式,因为我不知怎的把它忘了。(抱歉,某些移动设备没有波浪键!)