RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([0-9a-zA-Z_\-]+)(|\.html|\.php)$ page.php这是.htacess的规则。我想要的是,如果文件没有找到,然后重定向到page.php。例如,如果未找到url people.php、people.html,则重定向到page.php。
因为我也想要那些不带.php的文件名,比如人们先直接转到people.php。然后检查文件是否存在,如果不存在,则重定向到page.php。如何添加一条规则使用户重定向到people.php
发布于 2011-04-21 12:53:58
这些规则应该对你有效:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# if there is no . in request then append .php
# it is important to make [L] as last rule here
RewriteCond %{REQUEST_FILENAME} !\.
RewriteRule ^(.+)$ /$1.php [L]
# 404 handling for files that don't exist
# NC is for ignore case comparison
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^.]+\.(html|php)$ /page.php [L,NC]发布于 2011-04-21 12:07:50
看看这是否实现了您想要的结果:
RewriteEngine on
RewriteRule ^(?:.+/)?([^/.]+)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule \.(?:html|php)$ page.phphttps://stackoverflow.com/questions/5739265
复制相似问题