htaccess的基础上与通配符和东西后,到index.php index.php页面重定向不存在的页面 [英] .htaccess redirect non existing pages based on index.php page with wildcard and something after it to index.php
问题描述
请帮忙,一些网站随意添加动态查询字符串访问我的主页。
Please help, some website is arbitrarily adding dynamic query strings to my home page.
例如我的主页是www.mysite.com/index.php,他们链接到很多环节是这样的:
For example my home page is www.mysite.com/index.php and they link to many links like this:
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
And those links are opening on my site, content of page are the same for every page, just like my original www.mysite.com/index.php
有几百该链接指向我的网站。因此,如何我也可以把这样的:
There are few hundreds of that links pointing to my site. So how I can redirect this:
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文件
This what I tried so far in my .htaccess file
RedirectMatch 302 ^index.php?a= http://www.www.example-ste.com/
RewriteRule ^/index.php?a=(.*) http://www.example-ste.com/
不过还是页面打开的网站。
But still pages are opening on site.
另一个类似的问题。
如何重定向结尾页?pagewanted =所有同一个网页,但与出的?pagewanted =所有
How to redirect pages ending with "?pagewanted=all" to the same page but with out that "?pagewanted=all"
例如我需要重定向页面:
For example I need to redirect page:
www.mysite.com/something-something/something.html?pagewanted=all
到
www.mysite.com/something-something/something.html
您好。
我只是发现了一些。我需要的URL重定向规则将重定向像网页:
I just noticed something. I needed URL redirection rule which will redirect pages like:
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
到网站的主页上,根。你给了我这个code:
to home page of site, root. And you gave me this code:
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 =
例如在一些临时的网页所有链接我有这样的链接:
And I must say it works fine, it does that, but I just noticed that it somehow blocks or redirect all links containing ?a=
for example on some temporary pages I have links like:
i.php?a=something-something-something
所以,你能采取code只是基于类似的index.php页面:
So, can you adopt code just for pages based on index.php like:
www.mysite.com/index.php?a=something-something-something
而不是与链接:
and not for links with:
i.php?a=something-something-something
如果我是正确的它的工作原理与 A =
,但我只需要为所有链接的index.php?a =
If I am right it works on all links with "a=
" but I need just for "index.php?a=
"
推荐答案
尝试添加folloginw到你的.htaccess文件的顶部
Try adding the folloginw to the top of your .htaccess file
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 =所有
Edit.
Added rule to remove pagewanted=all
这篇关于htaccess的基础上与通配符和东西后,到index.php index.php页面重定向不存在的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!