【发布时间】:2015-02-26 07:04:57
【问题描述】:
我想重写请求以使用非常标准且有效的 index.php。
问题是包含 index.php 的旧链接现在无效,我想将它们重定向到我网站的根 url。
可能的重复项包括:Rewrite URL to index.php but avoid index.php in the URL,但提到的答案对我不起作用。
RewriteEngine on
# This results in a redirect loop
#Redirect 301 /index.php http://domain.com
# This gets me a 500 error
# RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
# RewriteRule ^index\.php/?(.*) / [L,R=301]
# Push www traffic to base domain. <<= Works
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# Final rewrite to include index.php <<= Works
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
网址:http://domain.com/index.php/component/fsf/?view=faq,应该是无效的,它应该返回一个 404 错误,但由于我当前的重写规则,网站访问者将看到主页。我想用 301 将它重定向到主页,以便可以从搜索索引中删除它。 任何帮助将不胜感激。
【问题讨论】:
标签: mod-rewrite