【发布时间】:2017-11-22 16:55:19
【问题描述】:
我有一个重写规则,但我希望重写规则仅在页面不是 index.php 时运行,我尝试使用 If 语句,但无济于事。我的代码,我尝试过的。
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^index$ ./index.php // i did a URL rewrite for removing the .php
<If "%{HTTP_HOST } == 'index'">
// do nothing here else
</If>
<Else> //run the code in the else statement.
RewriteRule ^ profile.php [NC,L]
RewriteRule ^profile/([0-9a-zA-Z]+) profile.php?id=$1 [NC,L]
RewriteRule ^ zprofile.php [NC,L]
RewriteRule ^zprofile/([0-9a-zA-Z]+) zprofile.php?id=$1 [NC,L]
</Else>
【问题讨论】:
-
将
index更改为实际网址。 -
@Lag 响应服务器错误。
-
@Chris85 谢谢,但我真的不明白,请你在下面给出一个例子作为可接受的答案。
-
@chris85:不,因为
%{HTTP_HOST}永远不可能是index。它的价值为ww.example.com -
@anubhava 啊,是的,这是有道理的。
标签: regex apache .htaccess mod-rewrite url-rewriting