Forum Moderators: phranque

Message Too Old, No Replies

301 redirect - wont work?

         

phill2000star

6:41 am on Nov 30, 2007 (gmt 0)

10+ Year Member



Hiya all,

I am trying to put a 301 redirect up to redirect spiders and customers on a website.

At the moment the current products are viewed in detail using a url like this.

http://www.domain.com/viewProduct?productID=AAAA55555

And the new page which displays the product detail is: -

http://www.domain.com/products/AAAA55555.html

Now so far I have the following but I can't seem to get it to work?

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*viewProducts\.php?\ HTTP/ [NC]
RewriteRule ^(.*)viewProducts?productID=$ products/$1.html [R=301,L]

Any suggestions?

PS.

The re-write for the first url I typed is below

RewriteRule ^products/(AA(AB¦CD¦EF)[0-9]{5})\.html$ view_detail.php?product_id=$1 [NC,L]

phranque

7:58 am on Nov 30, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



viewProduct, viewProducts or view_detail?
.php or not?
productID or product_id?

you have so much going on it's hard to tell what is what.

what do the urls on your page look like?
what would you like the redirected url to look like?

phill2000star

3:03 pm on Nov 30, 2007 (gmt 0)

10+ Year Member



Sorry Phranque,

I posted that at about 6:30 this morning when I couldnt sleep!

At the moment the client has a website, and to view products in detail the URL is...

http://www.domain.com/viewProduct.php?productID=AAAA55555

With the re-development and SEO optimising I have started to completely overhall the site, and now I have the new url like this...

http://www.domain.com/products/AAAA55555.html

This is the URL that browsers point to. This is provided using a re-write which is...

RewriteRule ^products/(AA(AB¦CD¦EF)[0-9]{5})\.html$ view_detail.php?product_id=$1 [NC,L]

It basically makes it look as if there is a static .html page for each product, whereas it is actually parsed on the fly by calling the view_detail.php file passing the variable product_id in the query string.

This is setup and working fantastically, but when we put the new site online we will end up being penalised for the search engines as the page no longer exists for the products. The last thing we want is to go lower in the rankings (as the aim is to travel in the opposite direction...Upwards!).

So what I am trying to do is setup a 301 redirect so that the search engine spiders log the fact the page no longer exists (301) and to be redirected to the new product page.

To achieve this I have started to write the condition for it, but cannot get my head around it!

Here is what I have...

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*viewProducts\.php?\ HTTP/ [NC]
RewriteRule ^(.*)viewProducts?productID=$ products/$1.html [R=301,L]

As you may not be able to see I am trying to redirect ALL requests to the old page...

http://www.domain.com/viewProducts.php?productID=AAA55555

to the new page

http://www.domain.com/products/AAAA55555.html

Does this make more sense?

Thankyou and apologies for the poor explanation to start!

jdMorgan

3:25 pm on Nov 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem that's confusing us (and possibly causing your problem as well) is that your new rule patterns do not not match the URLs you posted that you want to rewrite and redirect.

At the moment the current products are viewed in detail using a url like this.

http://www.example.com/viewProduct?productID=AAAA55555

Now so far I have the following but I can't seem to get it to work?

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*viewProducts\.php?\ HTTP/ [NC]
RewriteRule ^(.*)viewProducts?productID=$ products/$1.html [R=301,L]

The re-write for the first url I typed is below
RewriteRule ^products/(AA(AB¦CD¦EF)[0-9]{5})\.html$ view_detail.php?product_id=$1 [NC,L]


So we have viewProduct, viewProducts, and view_detail.
In order to have a productive discussion, the problem description needs to be internally consistent, so please address this and tell us what the actual URLs are.

There's a technical problem with your redirect rule, but there's no use discussing it until we know the correct /consistent details.

Jim

[edited by: jdMorgan at 3:26 pm (utc) on Nov. 30, 2007]

phill2000star

4:13 pm on Nov 30, 2007 (gmt 0)

10+ Year Member



Sorry,

Lack of sleep within 48 hours and caffeine levels are making my concentration extremely low.

Appologies guys, I know for you to help me, I have to help you!

Right.... 3rd attempt

Here is what I have...

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*viewProduct\.php?\ HTTP/ [NC]
RewriteRule ^(.*)viewProduct?productID=$ products/$1.html [R=301,L]

As you may not be able to see I am trying to redirect ALL requests to the old page...

http://www.domain.com/viewProduct.php?productID=AAA55555

to the new page

http://www.domain.com/products/AAAA55555.html

Does this make more sense?

jdMorgan

4:38 pm on Nov 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We still have an inconsistency here between view_detail.php and viewProduct.php, so I'll have to leave that to you to sort out. Unless the script name has changed, these script paths should be consistent in the rules below.

# Internally rewrite new static URLs to dynamic filepath
RewriteRule ^products/(AA(AB¦CD¦EF)[0-9]{5})\.html$ /view_detail.php?product_id=$1 [NC,L]
#
# Externally redirect (only) direct client requests for dynamic URLs to corresponding static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /viewProduct\.php\?productID=([^&\ ]*)\ HTTP/ [NC]
RewriteRule ^viewProduct\.php$ http://www.example.com/products/%1.html[b]?[/b] [NC,R=301,L]

Jim

[edit] Corrected as noted below [/edit]

[edited by: jdMorgan at 4:56 pm (utc) on Dec. 29, 2007]

g1smd

8:25 pm on Dec 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have held off answering this until I am sure what the question actually is...

phill2000star

4:18 pm on Dec 29, 2007 (gmt 0)

10+ Year Member



Hi,

yeah I had got confused myself between viewProduct and viewProducts lol....

It is fine, however it is now appending?productID=AAAA00000 to the end of the new page's url.

EG.

[domain.com...]

How can I get it not to do this?

jdMorgan

4:58 pm on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops! I always forget that... Add the question mark to the substitution URL as shown in the corrected code above. This question mark will not "show" in the redirected URL; It is only a 'token' that tells mod_rewrite to clear the query string.

Jim

g1smd

10:43 pm on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I find it helpful to start a list of all the URL formats that you want to be valid, and all the ones that your server will return content for, but which should not.

Months later, it can be very useful in understanding what you decided a long time ago.