Search code examples
.htaccesshttp-redirectampersand

.htaccess Removing ampersand from URL?


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.


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]