Page 1 of 1

301 redirect with PHP variables in URL

Posted: Fri Mar 18, 2011 10:38 pm
by curseofthe8ball
We need to redirect a URL to a new URL but we can't get it to work and I believe it is due to the inclusion of variables in the URL.

For example, we need to redirect http://www.domain.com/attorneydetail...tion=view&id=8 to http://www.domain.com/practiceareas....tion=view&id=2

How would we do this in a .htaccess file?

Re: 301 redirect with PHP variables in URL

Posted: Sat Mar 19, 2011 2:15 am
by divedj
Try

REDIRECT 301 /attorneydetail...tion=view&id=8 http://www.domain.com/practiceareas....tion=view&id=2

Make sure you have a single space between the elements and dont include a http://www.domain.com in the first part where you tell which page to redirect.

Re: 301 redirect with PHP variables in URL

Posted: Mon Mar 21, 2011 12:46 am
by curseofthe8ball
divedj,

Thanks for the reply. Unfortunately that doesn't seem to work. It works fine if I make it:

REDIRECT 301 /attorneydetails.php http://www.domain.com/practiceareas.php ... =view&id=2

But that isn't what we need. Something seems to get messed up when we pass the ?action=view&id=8 part in first URL element.

Re: 301 redirect with PHP variables in URL

Posted: Tue Mar 22, 2011 5:07 am
by divedj
Sorry, just learned something myself.

The REDIRECT comand only looks at path/file not at querystrings of a given URL
you may have to look into modrewrite.

RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]&)*id=8(&|$)
RewriteRule ^$ http://www.domain.com/attorneydetail...tion=view&id=2 [R=301,L,QSA]

A pretty good basic explanation of mode rewrite you find here http://www.yourhtmlsource.com/sitemanag ... iting.html