简体   繁体   English

使用Htaccess使用参数重定向URL

[英]Redirect Urls With Parameters Using Htaccess

I did a "site:" command in google to view the indexed urls and found a lot of urls with parameters all pointing to the same page. 我在Google中执行了“ site:”命令来查看索引的url,发现很多带有参数的url都指向同一页面。

Its a static site, but about 5 years ago it was a Wordpress site, which may be how those links were created and indexed by Google. 它是一个静态网站,但是大约5年前它是一个Wordpress网站,可能是Google创建和链接这些链接的方式。 The 3 main links I found are as follows. 我发现的3个主要链接如下。 They all look like these 3 but with different id's. 它们看起来都像这3个,但具有不同的ID。

http://example.com/index.php?option=com_banners&task=click&bid=41 http://example.com/index.php?option=com_banners&task=click&bid=41

http://example.com/?option=com_content&view=article&id=86&Itemid=201 http://example.com/?option=com_content&view=article&id=86&Itemid=201

http://example.com/phlebotomy-jobs?&pid=6774238282444518&q=Phlebotomy&pg=7 http://example.com/phlebotomy-jobs?&pid=6774238282444518&q=Phlebotomy&pg=7

My question is how do I redirect these links, with all of the different parameter ids, to their corresponding pages. 我的问题是如何将这些链接以及所有不同的参数ID重定向到其相应的页面。 The first two go to the homepage and the 3rd one goes to a /phlebotomy-jobs page. 前两个进入首页,第三个进入/ phlebotomy-jobs页面。

So, what I'm looking for is, for example, this url: http://example.com/phlebotomy-jobs?&pid=6774238282444518&q=Phlebotomy&pg=7 to redirect to http://example.com/phlebotomy-jobs 因此,例如,我要查找的是以下URL: http : //example.com/phlebotomy-jobs?& pid= 6774238282444518& q= Phlebotomy&pg=7重定向到http://example.com/phlebotomy-jobs

Basically removing everything from the ? 基本上从中删除所有内容? on. 上。

RewriteEngine On
RewriteRule ^index.php?$ /path/page.php [R=301,L,QSA]
RewriteRule ^$ /path/page.php [R=301,L,QSA]
RewriteRule ^phlebotomy-jobs?$ /path/page.php [R=301,L,QSA]

The QSA RewriteRule Flag appends the query string. QSA RewriteRule标志附加查询字符串。

https://httpd.apache.org/docs/2.4/rewrite/flags.html https://httpd.apache.org/docs/2.4/rewrite/flags.html

Edit: 编辑:

Since you're not concerned with retaining the query strings: 由于您不关心保留查询字符串:

RewriteEngine On
RewriteCond %{REQUEST_URI} (^/index.php$|^/$|^/phlebotomy-jobs$)
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) /$1? [R=301,L]

Note: This method prevents passing any query strings to either of those two pages. 注意:此方法可防止将任何查询字符串传递到这两个页面中的任何一个。

Well, not sure if it's the "best" way, but this, for example, works: 好吧,不确定这是否是“最佳”方法,但是,例如,这可行:

RewriteCond %{QUERY_STRING} option=
RewriteRule (.*) /$1? [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM