Click to See Complete Forum and Search --> : htaccess 301 redirects with query strings


efru
07-28-2008, 07:21 PM
Hi There

My question is a htaccess problem, so I hope someone can help. Basically my old site had urls such as :
http://www.example.com/press_release.php?press_id=1

Now, on my new site, I want them to go to :
http://www.example.com/press_releases/press_name_here/

My trouble is with that query string. I've trolled a hundred forums today and nothing is appearing to work. I've tried escaping the question mark, various {QUERY_STRING} conditions, etc. Maybe I was just doing it wrong...I don't know.

Any help would be much appreciated.

Thanks in advance

hex1a4
08-05-2008, 06:10 PM
Hi,


RedirectMatch 301 /press_releases/(.*)(/?)$ http://domain.com/press_releases.php?press_id=$1

This will redirect domain.com/press_releases/1/ to domain.com/press_release.php?press_id=1
domain.com/press_releases/100/ to domain.com/press_release.php?press_id=100
etc.

You can also do URL rewrites?


RewriteRule ^press_releases/(.*)(/?)$ /press_release.php?press_id=$1 [R=301,L]

This will work the same as above

Or, if you don't want to redirect and instead have the new URL in the address bar, remove R=301 from the RewriteRule

Jo6891
07-05-2010, 11:07 AM
Hi there...

Did you find a solution to this?? I'm having trouble myself in redirecting from a query string to a pretty URL.

I myselft have tried all sorts including:

RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^vpage.php$ %page.html? [R=302,L]

I can get normal redirects to work fine:

RewriteRule ^page\.php$ http://www.website.com/page.html [R=301,L]

Just not ones where the original address contains a query string.

I am using CMSMS which contains a default .htacces, which also contains the following code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Could this be a conflict??

Thanks in advance