为 ?index.php 重定向 301
Redirect 301 for ?index.php
我有一个简单的问题。我需要在我客户的 Joomla 安装中重定向奇怪的 URL。
我有一个像 example.com/?index.php
这样的 link,我需要重定向到 .htaccess
中的 example.com/
。
我尝试了以下方法,但它不起作用
Redirect 301 /?index.php /
尝试以绝对 URL 作为目标:
Redirect 301 /?index.php http://www.yourdomain.com/
example.com/?index.php
在这个URL中,index.php
在URL的查询字符串部分。你不能使用 mod_alias Redirect
来捕捉这个,你必须使用 mod_rewrite.
靠近 .htaccess
文件的顶部(在现有 RewriteEngine
指令之后)尝试以下操作:
RewriteCond %{QUERY_STRING} ^index\.php$
RewriteRule ^$ /? [R,L]
替换末尾的?
有效地从请求中删除了查询字符串。
这也是一个临时的 (302) 重定向,只有在您确定它工作正常时才将 R
更改为 R=301
。
我有一个简单的问题。我需要在我客户的 Joomla 安装中重定向奇怪的 URL。
我有一个像 example.com/?index.php
这样的 link,我需要重定向到 .htaccess
中的 example.com/
。
我尝试了以下方法,但它不起作用
Redirect 301 /?index.php /
尝试以绝对 URL 作为目标:
Redirect 301 /?index.php http://www.yourdomain.com/
example.com/?index.php
在这个URL中,index.php
在URL的查询字符串部分。你不能使用 mod_alias Redirect
来捕捉这个,你必须使用 mod_rewrite.
靠近 .htaccess
文件的顶部(在现有 RewriteEngine
指令之后)尝试以下操作:
RewriteCond %{QUERY_STRING} ^index\.php$
RewriteRule ^$ /? [R,L]
替换末尾的?
有效地从请求中删除了查询字符串。
这也是一个临时的 (302) 重定向,只有在您确定它工作正常时才将 R
更改为 R=301
。