【发布时间】:2017-03-13 10:25:33
【问题描述】:
我一直在尝试构建一个 if/else 分支逻辑,如下所示:
if ( <URL> corresponds to an existing file ( with the exception of those within the "server" directory ) ) {
don't modify <URL>
}
else if ( "pages/<URL>.(html|php)" corresponds to an existing file ) {
re-write it to that
}
else {
re-write the URL to index.php
}
这是我想出的.htaccess 文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^server/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ".*" "-" [L]
RewriteCond "pages/%{REQUEST_FILENAME}\.(html|php)" -f
RewriteRule "(.*)" "pages/%1.$1" [L]
RewriteRule ".*" "index.php" [L]
我遇到的问题是这样的:
当我访问server/lib/router.php 时,它会执行该脚本,而它应该执行index.php。
现在,我知道.htaccess 中的 L 标志触发了 URL 重写逻辑的另一次迭代,但我不明白这如何导致最后一个规则最终被执行。
【问题讨论】:
标签: php apache .htaccess mod-rewrite url-rewriting