htaccess add 301 永久移至 RewriteRule
我的 .htaccess 文件中有这条规则:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php
它的作用是将所有 url 的 index.php?somevar=# 重定向到 index.php,但是当它重定向时发送代码 302 而我希望它是 301。
我尝试添加RewriteRule 之后的
但它不起作用。[R=301]
。 /index.php
感谢一些帮助:-)
I have this rule in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php
what it does is to redirect all url's index.php?somevar=# to index.php, however when it redirect's sends out code 302 and i want it to be 301.
I tried to add [R=301]
after RewriteRule . /index.php
but it doesn't work.
Some help is appreciated :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这东西不符合你所描述的。您的规则将对不存在文件的每个请求发送到
index.php
。 URL:已经调用
index.php
。你不需要任何重写魔法来处理这个问题。另外...
也是一个不好的做法。它现在不会给您带来问题,但将来当您修改规则时可能会出现问题。你宁愿使用:
This thing does not do what you describe. Your rule sends every request to non-existent files to
index.php
. The URL:already calls
index.php
. You don't need any rewrite magic to handle that.Also ...
is a bad practice. It does not cause you problems now, but it could in the future, when you modify the rules. You'd rather use: