Forum Moderators: phranque

Message Too Old, No Replies

301 non-www to www solution?

Anybody see anything wrong with it?

         

Halo2Boards

9:02 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



Anybody see anything wrong with this 301 solution for resolving yourdomin.com to www.yourdomain.com

This is in the .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.*
RewriteRule ^(.*) [yoursite.com...] [R=301,L]

ChadSEO

9:24 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



Looks good to me. I'm doing almost the exact same thing, and it works fine:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.net
RewriteRule ^(.*)$ [mydomain.net...] [R=301,L]

andy_boyd

1:15 am on Jul 6, 2005 (gmt 0)

10+ Year Member



I'm using pretty much the same code and it works just fine. However, if you already have a non-www and www version of your site in the SE's it will take them a while to update.

On a similar note ... does anybody know how I can redirect www.example.com/index.php -> www.example.com/ because everything I've tried fails. :(

Dijkgraaf

1:40 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well you can always put a bit of code in your index.php that checks $_SERVER['REQUEST_URI'] first and if it has index.php issue the following headers
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
header("Connection: close");