Forums / General Questions / redirect obsolete links to a different page?

redirect obsolete links to a different page?

Locked

Views: 9,299

Results 21 to 27 of 27
This thread is locked. New replies are disabled.
3 May 2010, 1:18 PM
#21
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
415
Plugin Contributions:
0

redirect obsolete links to a different page?

g1smd:

Please disregard the post immediately above.

You'll need this in the root .htaccess file:```
RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^zencart/(index.php)?$ http://www.example.com/ [R=301,L]

> 
> This redirects product ID 221 for all categories, for both www and non-www requests, and whether or not "index.php" is within the request.
> 
> Change "zencart/" to your real folder name. Remove the "zencart/" part if the site is in the root folder. Note the trailing slash is also deleted.
> 
> Final point. Never mix RewriteRule directives with Redirect or RedirectMatch directives within the same site. If you do, you can never be quite sure of the processing order. By mixing them up, you're using directives from two different Apache modules. Stick to just using RewriteRule for all directives.


Thanks for the info, however its still not redirecting my specific product page. 
Here is what I do:

I want to redirect:

http://www.example.com/index.php?main_page=product_info&cPath=68&products_id=218


to <https://www.example.com>, so in my root htaccess I write:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=218$ [NC]
RewriteRule ^(index.php)?$ [url]http://www.example.com/[/url] [R=301,L]


When I then go to 

http://www.example.com/index.php?main_page=product_info&cPath=68&products_id=218


the page keeps trying to load for about 3 - 4 minutes whereafter the pages finally loades with the product ID 218.

Any ideas what Im doing wrong?
3 May 2010, 1:33 PM
#22
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

One small typo in the original code.

Add a question mark to the end of the http://www.example.com/ part to clear the query string value.```
RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^(index.php)?$ http://www.example.com/[b]?[/b] [R=301,L]
or
RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^[b]zencart//b?$ http://www.example.com/[b]zencart/?[/b] [R=301,L]

Online since 1995.

3 May 2010, 2:11 PM
#23
dml73 avatar

dml73

Zen Follower

Join Date:
Oct 2007
Posts:
415
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

Great! Thanks a lot! I have been trying to get this to work for a while now. Finally its working! :bigups:

3 May 2010, 2:27 PM
#24
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

Apologies for the initial typo.

A question mark on the end of any RewriteRule target clears the query string.

With the typo in place, a request for
www.example.com/**index.php**?main_page=product_info&cPath=68&products_id=218
would be redirected to
www.example.com*/?main_page=product_info&cPath=68&products_id=218
which still matches the pattern so is redirected to
www.example.com
/?*main_page=product_info&cPath=68&products_id=218
and this redirect continues until the browser gives up.

At this point, I'll recommend adding the Live HTTP Headers extension for Mozilla-based browsers such as Seamonkey and Firefox as it can save many hours of work. It shows the HTTP transactions between your browser and the server, and would show what was happening here within seconds. It is a vital tool for debugging server configuration of rewrites and redirects.

Online since 1995.

3 May 2010, 2:38 PM
#25
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

Regarding this part of the pattern```
&products_id=[b]221[/b]$




If you have multiple IDs to redirect, you can use a local OR within the RewriteCond like this:```
&products_id=(221|345|378|505)$
``` and it will process faster than having multiple rules.

If you have more than about ten to fifteen IDs to redirect, then split the rest into extra Conditions and add the [OR] flag.

Be aware of further shortcuts such as```
&products_id=2(20|45|55)$
```which redirects 220, 245, and 255 and ```
&products_id=23?45$
``` which redirects 245 and 2345.

Use these logical operators to their full advantage wherever possible.

Online since 1995.

30 Jun 2010, 4:01 PM
#26
mjpwall avatar

mjpwall

New Zenner

Join Date:
Nov 2009
Posts:
26
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

Hello all,

I'm trying to do something very similar, except instead of the home page I want to redirect the products to a particular category, tried adding the url inplace of index.php in the code but it doesn't work.

any ideas.

17 Sep 2011, 2:09 PM
#27
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: redirect obsolete links to a different page?

Instead I would redirect obsolete url
http://www.100asa.it/zebra-stampante-barcode-eltron-tlp-2844-p-185.html
to new products url:
http://www.100asa.it/zebra-stampante-barcode-eltron-tlp-2844-p-3237.html

I've try with

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=185$ [NC]
RewriteRule ^(.*)$ http://www.100asa.it/zebra-stampante-barcode-eltron-tlp-2844-p-3237.html [R=301,L]

but none, it don't work.