我在Apache重写规则方面遇到了一些问题。
在我的网络服务器上,以下文件包含前导" s
"存在(exerpt):
search.php
stats.php
status.php
现在,我想将search.php
重写为s
。
但是,当我现在致电status.php
时,我的search.php
被包含在内。
RewriteEngine on
RewriteRule ^stats$ stats.php
RewriteRule ^status$ status.php
RewriteRule ^s search.php # <---
RewriteRule ^live$ live.php
RewriteRule ^about$ about.php
RewriteRule ^i$ item.php
RewriteRule ^compare$ compare.php
DirectoryIndex home.php
如果网址类似
,我如何强制Apache仅将search.php
重写为s
http://localhost/s/PARAM1/...
我试了RewriteRule ^s/ search.php
但没有成功。
编辑:.../s/PARAM1/...
,stats
等处的404错误有效。
我希望您能理解我的问题,尽管我对重写规则不是很熟悉。
答案 0 :(得分:0)
重新排序您的规则并使用正则表达式来减少您的规则:
DirectoryIndex home.php
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(statu?s|live|about|compare)$ $1.php [L,NC]
RewriteRule ^i$ item.php [L,NC]
RewriteRule ^s/ search.php [L,NC]