Forum Moderators: phranque

Message Too Old, No Replies

My .htaccess returns a 302 Re-direct

I am trying to implement a 301 redirect

         

bfree74

5:19 pm on Oct 30, 2007 (gmt 0)

10+ Year Member



I am trying to implement a 301 re-direct for the canonical version of my URL. While the re-direct does work, it is returning a 302 message. I have added the code from my htaccess file below ... can someone help me?

Options +FollowSymlinks
RewriteEngine On
# Redirect all non-canonical domain requests to requested resource in canonical domain
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/ [R=301,L]

Philosopher

5:28 pm on Oct 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I can't help you with the 302 issue as the code you supplied seems as though it should issue a 301.

I can tell you that, with the code you supplied a request for the non-www version of ANY URL on your site will be redirected to the homepage which is not what you want.

You want to redirect the request of a non-www URL to the www version of that URL. I've included the updated rewrite for that below.

rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]