.htaccess htaccess-仅在“如果”时重写/&引用;(斜杠)包含

.htaccess htaccess-仅在“如果”时重写/&引用;(斜杠)包含,.htaccess,.htaccess,我对Apache重写规则有一些问题 在我的Web服务器上,存在以下带前导“s”的文件(exerpt): 现在,我想将search.php重写为简单的s。 但是当我现在调用status.php时,我的search.php被包括在内 RewriteEngine on RewriteRule ^stats$ stats.php RewriteRule ^status$ status.php RewriteRule ^s search.php # <--- RewriteRule

我对Apache重写规则有一些问题

在我的Web服务器上,存在以下带前导“
s
”的文件(exerpt):

现在,我想将
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
我尝试了
重写规则^s/search.php
,但没有成功。 编辑:404错误位于
../s/PARAM1/…
stats
等工作正常


我希望您能理解我的问题,尽管我对重写规则不是很熟悉。

重新排列规则,并使用正则表达式减少规则,如下所示:

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]

RewriteRule^s/search.php
rule的错误是什么?我得到了一个404错误。我认为url中缺少您的项目名称,您应该有如下内容:
http://localhost/myproject/s
Naa,“本地主机”只是一个例子。我不想发布真实的URL,因为它看起来像是广告发布您的完整.htaccess
http://localhost/s/PARAM1/...
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]