我需要为mod重写URL规则编写一个条件,以检测正在执行的页面。
我使用的RewriteRule
运行良好,但问题是我需要对两个不同的URL使用相同的规则。
RewriteRule ^testing/([^/]*)$ /index.php?url=$1&name=&submit=submit [NC,L]
RewriteRule ^testing/([^/]*)$ /test.php?url=$1&name=&submit=submit [NC,L]
在没有设置任何重写条件的情况下,当在浏览器中添加example.com/testing/
时,无论我在index.php
还是test.php
上,都会使用htaccess
中的第一个RewriteRule
。
以下是我尝试过的一些RewriteCond
:RewriteCond %{REQUEST_FILENAME} /test.php$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' (test'.php)/ [NC]
RewriteCond %{THE_REQUEST} 's/+(test'.php)/ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]+' /test'.php/
下面是完整的htaccess文件代码:
Options +FollowSymLinks
RewriteEngine on
## check if on index.php ##
RewriteCond %{THE_REQUEST} ^.*'/index.php'/.*$ ## not working ##
## if on index.php do this ##
RewriteRule ^testing/([^/]*)$ /index.php?url=$1&name=&submit=submit [NC,L]
## check if on test.php ##
RewriteCond %{THE_REQUEST} ^.*'/test.php'/.*$ ## not working ##
## If on test.php do this ##
RewriteRule ^testing/([^/]*)$ /test.php?url=$1&name=&submit=submit [NC,L]
如何让第一个(index.php(rewriteRule
在index.php
上工作,但在test.php
页面上忽略第一个规则并使用第二个规则?
谢谢:(
编辑:只是澄清一下。我不想重定向。我只想根据我所在的页面更改testing/
的值。正如我提到的,rewriteRule已经很好了。
## If on index.php ##
RewriteRule "^/index'.php$" "/index.php?url=$1&name=&submit=submit" [R,L]
试试这个
RewriteEngine On
#Checking if /index.php/ apears in URI
RewriteCond %{REQUEST_URI} ^(.*)'/index'.php'/(.*)$ [NC]
RewriteRule ^(.*)$ testing/index.php?url=$1&name=&submit=submit [NC]
这将显示index.php?url=sth1/index.php/sth2输出,而不是sth1/inindex.php/sth2
祝好运