【发布时间】:2018-05-05 15:09:39
【问题描述】:
当我尝试使用 if 语句在页面特定时运行 RewriteRule 时,我得到了 。我的 apache 服务器是 2.4,它也在我的屏幕截图中。我想在我的代码中做的是
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^index$ ./index.php
RewriteRule ^zindex$ ./zindex.php
RewriteRule ^logout$ ./logout.php
RewriteRule ^login$ ./login.php
RewriteRule ^zlogin$ ./zlogin.php
RewriteRule ^404$ ./404.php
#write if statement to check pages that is being loaded else fire for new username
<If "%{HTTP_HOST} == 'index.php' || %{HTTP_HOST} == 'ajaxsignlog.php' || %{HTTP_HOST} == 'ajaxsignlog1.php' || %{HTTP_HOST} == 'ajaxupload.php' || %{HTTP_HOST} == 'connect.php' || %{HTTP_HOST} == 'logout.php' || %{HTTP_HOST} == 'password.php' || %{HTTP_HOST} == 'top.php' || %{HTTP_HOST} == 'zindex.php' || %{HTTP_HOST} == 'ztop.php'">
// do not rewrite rule
</If>
<Else> //do some rewrite rules here
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>
【问题讨论】:
-
HTTP_HOST 将是 domain.com 而不是文件 neam
-
@nogad 谢谢,但我在本地主机上,请你为我举个例子。
-
"REQUEST_FILENAME 与请求匹配的文件或脚本的完整本地文件系统路径,如果在引用 REQUEST_FILENAME 时服务器已经确定了这一点。否则,例如在虚拟主机上下文中使用时, 与 REQUEST_URI 相同的值”httpd.apache.org/docs/2.4/expr.html
-
可能更容易像这样排除:
RewriteCond %{REQUEST_URI} !^/index\.php$ -
欺骗:stackoverflow.com/questions/14008003/… 和其他几十个人
标签: php apache .htaccess mod-rewrite