2011-12-16 102 views
0

请帮忙,有些网站会动态添加动态查询字符串到我的主页。.htaccess将基于index.php页面的非现有页面重定向到通配符后面的内容到index.php

例如我的主页是www.mysite.com/index.php并链接到许多环节是这样的:

www.mysite.com/index.php?a=something-something-something 
www.mysite.com/index.php?a=something-other 
www.mysite.com/index.php?a=some-other-thing 

而且这些链接打开我的网站,网页内容是相同的为每一页,就像我的原始www.mysite.com/index.php

有几百指向我的网站的链接。因此,如何我也可以把这样的:

www.mysite.com/index.php?a=something-something-something 
www.mysite.com/index.php?a=something-other 
www.mysite.com/index.php?a=some-other-thing 
... 

www.mysite.com/index.php或者只是www.mysite.com/

这是我试图在我的.htaccess文件至今

RedirectMatch 302 ^index.php?a= http://www.www.example-ste.com/ 
RewriteRule ^/index.php?a=(.*) http://www.example-ste.com/ 

但仍然页面在现场开放。


另一个类似的问题。

如何重定向与“pagewanted =所有?”在同一页但指出,结束页面“pagewanted =一切?”

比如我需要重定向页面:

www.mysite.com/something-something/something.html?pagewanted=all

www.mysite.com/something-something/something.html


你好。

我刚注意到一些东西。我需要URL重定向规则,这将重定向页面,如:

www.mysite.com/index.php?a=something-something-something 
www.mysite.com/index.php?a=something-other 
www.mysite.com/index.php?a=some-other-thing 

到网站,根的主页。而你给了我这个代码:

RewriteEngine On 
RewriteBase/

#if the query string has an a parameter 
RewriteCond %{QUERY_STRING} (^|&)a= [NC] 
#Redirect and remove query string parameters 
RewriteRule .* http://www.mysite.com/? [R=301,L] 

而且我必须说,它工作得很好,但它确实是,但我只注意到它在某种程度上阻止或重新定向含?a=例如对我有这样的联系一些临时网页所有链接:

i.php?a=something-something-something 

那么,你可以采用代码只是基于索引的页面。PHP这样的:

www.mysite.com/index.php?a=something-something-something 

,而不是与链接:

i.php?a=something-something-something 

如果我是正确的它适用于所有链接以“a=”,但我只需要为“index.php?a=

+0

有没有人有任何解决方案呢? – 2011-12-20 18:56:45

回答

2

尝试增加folloginw到您的.htaccess文件顶部

RewriteEngine On 
RewriteBase/

#if the query string has an a parameter 
RewriteCond %{QUERY_STRING} (^|&)a= [NC] 
#Redirect and remove query string parameters 
RewriteRule .* http://www.mysite.com/? [R=301,L] 

#if the query string has a pagewanted parameter 
RewriteCond %{QUERY_STRING} (^|&)pagewanted=all [NC] 
#Redirect and remove query string parameters for html pages 
RewriteRule (.+\.html) http://www.mysite.com/$1? [R=301,L] 

编辑。 添加规则删除pagewanted=all

+0

谢谢,它工作,它重定向到主页。 – 2011-12-16 15:48:39

相关问题