Question

I have been banging my head against a wall for a long time trying to figure out how to get rid of the last part of some of the URL's on my site. For example, I would like to rewrite this:-

http://www.mysite.com/335-protective-wrapping&page=prod

to this

http://www.mysite.com/335-protective-wrapping

There are about 2000 URL's with &page=prod at the end of them which I need to remove. Here's some more example URL's

http://www.mysite.com/335-protective-wrapping&page=prod
http://www.mysite.com/455-bubble-bags&page=prod
http://www.mysite.com/150-specialist-tapes&page=prod

I have tried many solutions but haven't come up with anything that works.

Any help would be much appreciated. Thanks.

Was it helpful?

Solution

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^([^&]+)&page=prod$ /$1 [L,R=301]

OTHER TIPS

This should work:

RedirectMatch 301 ^/(.*)&page=prod$ http://www.mysite.com/$1

If you really want to take into account the query part (after the ?) of the source-URI you have to use RewriteCond plus RewriteRule, you cannot just use RewriteRule. (http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)

Sorry, anubhava, that wont work for that reason.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top