Php 如果页面是特定的,如何在.htaccess中执行If语句

Php 如果页面是特定的,如何在.htaccess中执行If语句,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,当我尝试使用if语句运行RewriteRule时,当页面是特定的,我得到的是。我的apache服务器是2.4,它也在我的屏幕截图中。我想在代码中做的是 Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^index$ ./index.php RewriteRule ^zindex$ ./zinde

当我尝试使用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>
Options+FollowSymLinks
重新启动发动机
重写cond%{SCRIPT_FILENAME}-D
重写cond%{SCRIPT_FILENAME}-F
重写规则^index$./index.php
重写规则^zindex$。/zindex.php
重写规则^logout$。/logout.php
重写规则^login$./login.php
重写规则^zlogin$。/zlogin.php
重写规则^404$./404.php
#写入if语句,检查正在加载的页面是否有新用户名
//不要重写规则
//在这里重写一些规则
重写规则^profile.php[NC,L]
重写规则^profile/([0-9a-zA-Z]+)profile.php?id=$1[NC,L]
重写规则^zprofile.php[NC,L]
重写规则^zprofile/([0-9a-zA-Z]+)zprofile.php?id=$1[NC,L]
400错误请求是由
/
构造内的相对路径替换引起的。出于某种原因,在此上下文中添加回来的目录前缀始终是
*If/
(无论指令是在
还是
块中)-这可能会在执行内部重写时导致400错误请求(或在执行外部重定向时禁止403错误请求)

而且,在
/
构造中,
RewriteRule
模式与绝对文件系统路径匹配,而不是根相对URL路径。因此,上面的第二条指令永远不会匹配

因此,如果这些限制/差异影响您,那么不要同时使用mod_rewrite和Apache
表达式。在
表达式之外的指令如何受到影响方面还有其他问题。(就我个人而言,如果可能的话,我会尽量避免将两者混为一谈。)

另请参阅以下有关ServerFault的问题,该问题将更详细地介绍:

你不需要一个
/
表达式来做你想做的事情。mod_rewrite本身提供了实现这一点的机制,无需额外的工具。然而,具体如何实现这一点完全取决于您正在尝试做什么

在问题中的示例中,如果请求与一系列URL中的一个相匹配,您希望跳过一系列重写,则可以执行以下操作:

RewriteCond %{REQUEST_URI} =/index.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxsignlog.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxsignlog1.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxupload.php [OR]
RewriteCond %{REQUEST_URI} =/connect.php [OR]
RewriteCond %{REQUEST_URI} =/logout.php [OR]
RewriteCond %{REQUEST_URI} =/password.php [OR]
RewriteCond %{REQUEST_URI} =/top.php [OR]
RewriteCond %{REQUEST_URI} =/zindex.php [OR]
RewriteCond %{REQUEST_URI} =/ztop.php
RewriteRule ^ - [S=10]

# 10 Rules follow that are skipped when any of the above URLs are requested
# :
# :

RewriteRule
指令上的
S=10
标志指示当前面的任何URL完全匹配时跳过的完整规则数

有关如何在
.htaccess
中实现条件分支的更多想法,请参见以下问题:

HTTP\u主机将是domain.com而不是文件neam@nogad谢谢,但我是在localhost上,请你给我举个例子。“REQUEST_FILENAME匹配请求的文件或脚本的完整本地文件系统路径,如果在引用REQUEST_FILENAME时服务器已确定此路径。否则,例如在虚拟主机上下文中使用时,与REQUEST_URI“相同的值可能更容易排除,例如:
RewriteCond%{REQUEST_URI}!^/index\.php$
dupe of:anf几十个其他值
RewriteCond %{REQUEST_URI} =/index.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxsignlog.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxsignlog1.php [OR]
RewriteCond %{REQUEST_URI} =/ajaxupload.php [OR]
RewriteCond %{REQUEST_URI} =/connect.php [OR]
RewriteCond %{REQUEST_URI} =/logout.php [OR]
RewriteCond %{REQUEST_URI} =/password.php [OR]
RewriteCond %{REQUEST_URI} =/top.php [OR]
RewriteCond %{REQUEST_URI} =/zindex.php [OR]
RewriteCond %{REQUEST_URI} =/ztop.php
RewriteRule ^ - [S=10]

# 10 Rules follow that are skipped when any of the above URLs are requested
# :
# :