Click to See Complete Forum and Search --> : 301 Redirect


visualizer03
03-03-2010, 02:23 PM
I'm trying to set up a .htaccess redirect for a site I've inherited. It used to use php and strings - now it is straight xhtml.

The previous web address would be:
www.somesite.com/home_state.php?page=careers

The new address is:
www.somesite.com/careers.html

Everything I try for the 301 redirect goes to a 404 error.

For example:
Redirect 301 /home_state.php?page=careers http://somesite.com/careers.html

What else might I need in the .htaccess to make this work?

thewebhostingdi
03-04-2010, 11:27 PM
If you are getting the 404 error message you will have to check the apache server logs for the exact error message.

savaintl1@gmail
03-12-2010, 12:23 AM
this is not sufficient code for htaccess file you have to write proper code and you can find very easily on the web. Just try once.

visualizer03
03-15-2010, 04:53 PM
Thank you "thewebhostingdi" - the first error was that Shell was not enabled. I did that with the hosting company.

The next step was creating the right code. What I was looking for was not easily explained on any website that I could find. I had a dozen bookmarked links, none of which clearly explained what I needed. However, here is the solution - just in case others would use this post to learn:

First, make sure that this is included:
RewriteEngine On
RewriteBase /

Next, this piece of code will redirect all exact site name changes such as
www.somesite.com/home_state.php?page=careers
to www.somesite.com/careers.html

RewriteCond %{QUERY_STRING} page=(.+)
RewriteRule ^home_state\.php http://somesite.com/%1.html? [R=permanent,L]

For renamed redirects, use individual code like this:
RewriteCond %{QUERY_STRING} page=products1
RewriteRule ^home_state\.php http://somesite.com/products.html? [R=permanent,L]

The above code would redirect www.somesite.com/home_state.php?page=products1 to www.somesite.com/products.html