【发布时间】:2013-11-02 15:48:12
【问题描述】:
RewriteRule htaccess 上只有一个页面有问题:
页面http://www.snes-fr.net/staff.html 不工作 (404) 但所有其他页面都工作。
staff.php 在文件夹中:http://www.snes-fr.net/pages/staff.php
.htaccess 行:RewriteRule ^staff\.html$ index.php?page=staff [L]
但此链接无效:http://www.snes-fr.net/staff.html 这个正在工作:http://www.snes-fr.net/cgu.html
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]
...
我所拥有的都是在 RewriteRule 之后工作!
【问题讨论】:
-
我在 localhost 服务器中测试了这个重写规则,它确实有效。你的
.htaccess可能有另一部分搞砸了。你能完整地展示给我们看吗? -
除了 Guilherme 的评论:你为什么在这里使用 htmlspecialchars?您应该添加一个检查
if(realpath('pages/'.$page.'.php') == 'pages/'.$page.'.php')以拒绝路径遍历,即使index.php?page=../../some-other-php不可能 -
谢谢指教,我改了!并添加了 htaccess
标签: php .htaccess mod-rewrite http-status-code-404