URL重写不像预期的那样

时间:2014-09-14 09:47:06

标签: php apache .htaccess mod-rewrite url-rewriting

在我的整个页面链接都是从

重写的
    example.com/test.htm

    example.com/index.php?page=test

这很好用,但每当我想重写像

这样的链接时
    example.com/test/abc.htm

我希望它是

    example.com/index.php?page=test&id=abc
它根本不起作用。相反(取自$ _SERVER变量)我得到:

PHP_SELF现在是“test.php / abc.htm”

SCRIPT_NAME现在是“/test.php”而不是“/index.php”应该是什么

我根本不明白为什么会这样。 我的.htacces看起来像这样:

    Options +FollowSymlinks
    RewriteEngine on

    RewriteCond %{REQUEST_URI} !^/index.php$
    RewriteRule ^([^/]+)\.htm/?$ /index.php?page=$1 [L]
    RewriteRule ^test/([^/]+)\.htm/?$ /index.php?page=test&id=$1 [L]

提前感谢您提供任何帮助

1 个答案:

答案 0 :(得分:0)

您需要关闭MultiViews选项:

Options -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/.]+)\.htm/?$ index.php?page=$1 [L,QSA]
RewriteRule ^test/([^/.]+)\.htm/?$ index.php?page=test&id=$1 [L,QSA]