我对Apache重写规则有一些问题。
在我的the服务器上,存在以下带有前导"s“的文件(使用):
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如果URL如下所示,如何强制Apache只将search.php重写为s
http://localhost/s/PARAM1/...我试过RewriteRule ^s/ search.php,但没有成功。编辑: 404错误在.../s/PARAM1/...,stats等工作。
我希望你能理解我的问题,尽管我对重写规则不太熟悉。
发布于 2015-02-18 22:16:56
重新排序您的规则,并使用regex来减少您的规则如下:
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]https://stackoverflow.com/questions/28594643
复制相似问题