[英].htacces rewriteRule and rewriteCond not working correctly - why?
我尝试了以下操作,如果请求的文件存在,则重定向到php-script,如果不存在,则重定向到missed.php。 为什么不起作用? 即使文件存在,它总是重定向到missed.php
########################## if file exists #########################
# get requested filename
RewriteCond %{REQUEST_FILENAME} (.+)$
# use filename from line above and see if filename.php exists
RewriteCond %1\.php -f
# page standalone && includes index.php
RewriteRule (.+) $1.php [L]
# page included in index.php
#RewriteRule (.+) index.php?p=$1 [L]
#################### if file doesnt exits ###################
# get requested filename
RewriteCond %{REQUEST_FILENAME} (.+)$
# if filename.php doesnt exist
RewriteCond %1\.php !-f
# redirect to missed.php
RewriteRule (.+) missed.php [L]
请改用以下规则,因为REQUEST_FILENAME
对于不存在的文件不起作用:
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/test/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ missed.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.