2013-03-04 144 views
0

已经看过所有关于此的其他帖子,但似乎无法使其工作。有很多不相关的原因,为什么我无法更改Joomla配置,项目等,但无论如何,似乎这些应该工作,无论如何。htaccess重定向被“忽略”

总之,我想的itemid = 30在任何链接重定向到给出的一个。我究竟做错了什么?前三个是我试过的,最后一行是正在工作的。

RedirectMatch 301 ^Itemid=30$ http://inside.beta.oursite.com/index.php?option=com_cware&view=courses&Itemid=125 

redirect 301 index.php?option=com_cware&view=courses&Itemid=30 http://inside.beta.oursite.com/index.php?option=com_cware&view=courses&Itemid=125 

RewriteEngine On 
RewriteCond %{QUERY_STRING} Itemid=30 
RewriteRule ^Itemid=30/$ index.php?option=com_content&view=article&id=106&Itemid=121 [R=301] 


# If query string contains "username=admin" 
RewriteCond %{QUERY_STRING} username=admin 
# Block it without mercy 
RewriteRule .* - [F] 
+0

我在http://stackoverflow.com/questions/10135702/301-redirect-from-url-with-query-string-to-new-domain-with-different-query-找到解决方案 - 严格的,但不明白为什么重定向301 ....不工作,因为我低头并且它应该。 – GDP 2013-03-04 19:35:10

回答

1

RedirectRedirect仅考虑URL路径,其中排除了查询字符串。如果您想考虑查询字符串,则必须使用mod_rewrite

同样适用于RewriteRule

如果你想对阵的主机名,端口或查询字符串,使用的RewriteCond与%{HTTP_HOST}%{SERVER_PORT}或%{QUERY_STRING}变量分别。

因此,如果你想匹配一些查询字符串,所有的URL重定向到一些其他的URL,在组合使用的RewriteCond与重写规则

RewriteEngine On 
RewriteCond %{QUERY_STRING} Itemid=30 
RewriteRule .* index.php?option=com_content&view=article&id=106&Itemid=121 [R=301] 

这重定向任何URL .*Itemid=30查询字符串到index.php?option=com_content&...