不支持htaccess重写规则变量

时间:2015-02-25 15:23:39

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

我在php上重写规则有问题,我希望它是:

localhost/myproject/XXXX => localhost/myproject/index.php?request=XXXX

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /(.*)$ index.php?request=$1 [QSA,NC,L]
</IfModule>

我在apache上激活了mod_rewrite,我的index.php在WAMPDIR \ www \ MyProject下

我在这里测试时:http://htaccess.madewithlove.be/ 我明白了: enter image description here

请帮忙,谢谢

2 个答案:

答案 0 :(得分:1)

/myproject/.htaccess中使用此代码:

RewriteEngine On
RewriteBase /myproject/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?request=$1 [QSA,L]

RewriteRule之后不应该有正斜杠。

答案 1 :(得分:0)

你真的不必那么复杂。

这应该足够了:

RewriteEngine On
RewriteBase /myproject/
RewriteRule ^/(.+) /myproject/index.php?request=$1 [L]

我强烈建议您阅读有关htaccess的更多信息。即使它看起来像它也不是那么复杂。