2017-03-08 77 views
1

试图让从这个URL重定向:重定向工作只有第一次

http://www.mywebsite.it/it/component/fss/?view=admin_support 

这个网址:

http://www.mywebsite.it/it/index.php/component/fss/?view=admin_support 

我做了这个代码.htaccess文件:

RedirectMatch 301 ^/it/component/fss/?$ /it/index.php/component/fss/ 

所有的工作,如果我点击第一次的网址。网址开始/it/index.php/component但如果我点击进入该网页上的另一个链接(如http://www.mywebsite.it/it/component/fss/?view=list),我将重定向到网站主页。

但是,如果我复制地址(http://www.mywebsite.it/it/component/fss/?view=admin_support),我粘贴到另一个选项卡,重定向工作。

我该如何解决这个问题?

感谢

回答

0

使用mod_rewrite规则,而不是RedirectMatch匹配的查询字符串:

RewriteEngine On 

RewriteCond %{REQUEST_METHOD} !POST 
RewriteCond %{THE_REQUEST} \s/+it/(component/fss/?)\?view=[^&\s]+[&\s] [NC] 
RewriteRule^/it/index.php/%1 [L,R=301] 

确保测试这种变化之前,清除浏览器缓存。

+0

我试过你的代码,但结果与RedirectMatch相同 –

+0

在我的.htaccess中只有你的规则。我试着用私人窗口chrome和清除所有的cookie,如果我去的网址可以有'?view = admin_support'重定向工作到index.php,但如果我进入另一个ulr,可以有例如'? view = test'重定向不起作用。我尝试从你的规则中删除视图,但都停止工作。如何让alla页面将'it/component/fss /'重定向到'/ it/index.php/component/fss'?我的.htaccess是第一个forlder(httpdocs)。谢谢@anubhava –

+0

是的。只有'/ it/index.php/component/fss'包含'/ it/component/fss /'的页面。 –

0

尝试与私人窗口:

enter image description here

如果一切正常,你只需要清除浏览器缓存。

+0

已经尝试,但它不工作。 –