[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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>
0
cstormer
Asked:
cstormer
  • 5
  • 5
1 Solution
 
Tol_cvCommented:

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>
0
 
caterham_wwwCommented:
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]
0
 
cstormerAuthor Commented:
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>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Tol_cvCommented:
try it  with  RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R],
  instead of  RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R=301,L]
0
 
cstormerAuthor Commented:
that , tacked onto that line?
0
 
cstormerAuthor Commented:
Ya actually didn't work..
0
 
Tol_cvCommented:
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>
0
 
Tol_cvCommented:
0
 
cstormerAuthor Commented:
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?
0
 
Tol_cvCommented:
ok, then  :
 
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^chrisstormer\.com [NC]
RewriteRule ^(.*)$ http://www.chrisstormer.com/$1 [R,L] ### all requests reditected to www and that's all

  #RewriteCond %{REQUEST_FILENAME} !-f          this you don't need  redirect all to www
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteRule ^ /index.php [L]
</IfModule>
0
 
cstormerAuthor Commented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now