Link to home
Start Free TrialLog in
Avatar of Chris Stormer
Chris Stormer

asked on

domain.com to www.domain.com 301 redirect.. or mod_rewrite... in .htacces

I am attempting to redirect...

chrisstormer.com to www.chrisstormer.com ... I don't really care how it's done.. but I was trying to use a mod_rewrite.. but a 310_redirect is also excellent.. can anybody help? I want all url's on the domain to redirect also.. to the www version... this is what I have right now and it's not working...


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# THIS IS MY CODE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.chrisstormer.com$ [NC]
RewriteRule ^(.*)$ chrisstormer.com/$1 [R,L]
</IfModule>
Avatar of Tol_cv
Tol_cv


Try it like this :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.chrisstormer.com$ [NC]
RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R,L]
</IfModule>
You must make sure that your order is correct. So force the 301 status code, dass =301 to the r flag

You're using two times the same code, that doesn't make a difference to the result but creates processing.

That should be enough:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^chrisstormer\.com [NC]
RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
Avatar of Chris Stormer

ASKER

This does accomplish what I wanted.. ALMOST... but it only does it at the root level.. so for example..

http://chrisstormer.com/history/designs points to http://www.chrisstormer.com/index.php

Is there a way to adjust it so that
http://chrisstormer.com/history/designs points to http://www.chrisstormer.com/history/designs

Also..  my final .htaccess file looks like this... now.. should I remove anything?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


# END WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^chrisstormer\.com [NC]
RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
</IfModule>
try it  with  RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R],
  instead of  RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R=301,L]
that , tacked onto that line?
Ya actually didn't work..
hmm ..  if http://chrisstormer.com/history/designs/ works and http://chrisstormer.com/history/designs/ doesn't your problem is with trailing slashes see
- http://rosebud.stanford.edu/manual/misc/rewriteguide.html   You need another rule to add / at the end of  url requested

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^chrisstormer\.com [NC]
RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R=301,L]

RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           $1/  [R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
</IfModule>
http://chrisstormer.com/history/designs/  redirects to the index.php file.. not way just to add teh www. and keep the rest of the url the same?
ASKER CERTIFIED SOLUTION
Avatar of Tol_cv
Tol_cv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tol,

Really appreciate all your help here.. I'm just not sure why this is not working...

Check this...

http://chrisstormer.com/2006/05/27/pandora-foxy-tunes-this-is-the-life/

It redirects that url to http://www.chrisstormer.com/index.php