Apache L|Last 标志不停止循环


Apache L|Last flag not stopping the loop

我正在重写特定页面访问的请求,但我想为几个页面添加排除项。假设,我希望我的请求 site.com/page/test 转到 site.com/page.php?str=test,但我想向一个字符串添加一个排除项,以便不转到该页面,而是转到另一个页面,例如:site.com/page/contact 应该转到 site.com/contact.php

这就是我尝试的方式:

RewriteRule ^static/mobile_app/?$ static/mobile_app.php [QSA,L]
RewriteRule ^static/([a-zA-Z0-9%.'-_]+)/?$ static/page.php?url_key=$1 [QSA,L]

我在文件末尾也有这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /static/page.php?url_key=404 [L]

一件奇怪的事情是,如果我尝试以下规则,它会起作用:

RewriteRule ^static/mobile_app.php$ static/mobile_app.php [QSA,L]
RewriteRule ^static/([a-zA-Z0-9%.'-_]+)/?$ static/page.php?url_key=$1 [QSA,L]

意味着,如果我尝试用扩展名编写完整的文件名,它可以工作。有人可以帮忙吗?谢谢。

像这样完成完整的DOCUMENT_ROOT/.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+(.+?)'.php['s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteRule ^static/(['w.-]+)/?$ static/page.php?url_key=$1 [QSA,L,NC]
## To internally redirect /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /static/page.php?url_key=404 [L,QSA]