Php .htaccess只有一个重写规则不起作用
我对“重写规则”访问中的只有一个页面有问题:Php .htaccess只有一个重写规则不起作用,php,.htaccess,mod-rewrite,http-status-code-404,Php,.htaccess,Mod Rewrite,Http Status Code 404,我对“重写规则”访问中的只有一个页面有问题: SetEnv PHP_VER 5_4 ErrorDocument 404 http://www.snes-fr.net/404.html RewriteEngine on Options +FollowSymlinks SetEnv REGISTER_GLOBALS 1 SetEnv MAGIC_QUOTES 0 RewriteCond %{HTTP_REFERER} decerto\.fr [NC] RedirectMatch seeothe
SetEnv PHP_VER 5_4
ErrorDocument 404 http://www.snes-fr.net/404.html
RewriteEngine on
Options +FollowSymlinks
SetEnv REGISTER_GLOBALS 1
SetEnv MAGIC_QUOTES 0
RewriteCond %{HTTP_REFERER} decerto\.fr [NC]
RedirectMatch seeother ^/dossier-super-nintendo_([0-9]+)_(.*)\.html$ http://www.snes-fr.net/tests.html
#REECRITURE
RewriteRule ^staff\.html$ index.php?page=staff [L]
RewriteRule ^cgu\.html$ index.php?page=cgu [L]
RewriteRule ^contact\.html$ index.php?page=contact [L]
RewriteRule ^404\.html$ index.php?page=404 [L]
RewriteRule ^index\.html$ index.php [L]
页面不工作(404),但所有其他页面都正常
staff.php位于以下文件夹中:
.htaccess行:重写规则^staff\.html$index.php?page=staff[L]
但这个链接不起作用:
这一个正在工作:
RewriteRule^cgu\.html$index.php?page=cgu[L]
显示页面的代码
$page = @htmlspecialchars($_GET['page'], ENT_QUOTES);
if(is_file('pages/'.$page.'.php'))
{
require('pages/'.$page.'.php');
}
你有什么线索吗?多谢各位
编辑:htaccess:
SetEnv PHP_VER 5_4
ErrorDocument 404 http://www.snes-fr.net/404.html
RewriteEngine on
Options +FollowSymlinks
SetEnv REGISTER_GLOBALS 1
SetEnv MAGIC_QUOTES 0
RewriteCond %{HTTP_REFERER} decerto\.fr [NC]
RedirectMatch seeother ^/dossier-super-nintendo_([0-9]+)_(.*)\.html$ http://www.snes-fr.net/tests.html
#REECRITURE
RewriteRule ^staff\.html$ index.php?page=staff [L]
RewriteRule ^cgu\.html$ index.php?page=cgu [L]
RewriteRule ^contact\.html$ index.php?page=contact [L]
RewriteRule ^404\.html$ index.php?page=404 [L]
RewriteRule ^index\.html$ index.php [L]
我所有的一切都是为了工作 您的线路是正确的,问题必须来自htaccess中的其他地方。 你能分享文件的其余部分吗 但是,请注意,不应使用htmlspecialchars来保护您的需求。
您可以使用函数basename:对所有页面使用一行代码不是更容易吗? 差不多
RewriteRule ^(.*)\.html$ index.php?page=$1 [L]
我相信这是因为
MultiViews
根据:
使用“多视图”搜索,其中服务器进行隐式文件名模式匹配,并从结果中进行选择。
尝试在上关闭它。htaccess
:
Options +FollowSymLinks -MultiViews
我在一个本地主机服务器上测试了这个重写规则,它确实有效。您的
.htaccess
可能还有另一部分搞乱了。除了Guillerme的评论:你为什么在这里使用htmlspecialchars?如果(realpath('pages/'.$page..php')=='pages/'.$page..php')拒绝路径遍历,您应该添加一个检查if(realpath('pages/'.$page..php')
),即使index.php?page=../../php其他一些php
不可能谢谢您的建议,我更改了它!添加了htaccess刚刚添加了htaccess!我试图删除RedirectMatch
,员工热线正在工作。。。但是,我没有看到我的错误…呵呵,没有,因为我使用了其他重写规则,使用了其他var!