简体   繁体   English

htaccess重写规则变量不受支持

[英]htaccess rewrite rule variable is not supported

I have a problem with a rewrite rule on php, I want it to be: 我对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>

I activated mod_rewrite on apache and my index.php is under WAMPDIR\\www\\MyProject 我在Apache上激活了mod_rewrite,而我的index.php在WAMPDIR \\ www \\ MyProject下

When I test it here: http://htaccess.madewithlove.be/ I get this: 当我在这里进行测试时: http : //htaccess.madewithlove.be/我得到了: 在此处输入图片说明

Please help, thanks 请帮忙,谢谢

Have this code in /myproject/.htaccess : /myproject/.htaccess有以下代码:

RewriteEngine On
RewriteBase /myproject/

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

There should not be a leading slash right after RewriteRule . RewriteRule之后不应该有一个斜杠。

You really don't have to make it that complicated. 您实际上不必使其变得如此复杂。

This should suffice: 这样就足够了:

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

I strongly recommend that you read more about htaccess. 我强烈建议您阅读有关htaccess的更多信息。 It's really not that complicated even though it might look like it. 即使看起来很复杂,实际上也没有那么复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM