"no www" -> "www" Redirect 301 problem

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
steelexus
New Member
New Member
Posts: 5
Joined: Wed May 25, 2011 3:07 pm

"no www" -> "www" Redirect 301 problem

Post by steelexus »

Hi.

I'am trying to do a "no www" to "www" 301 redirect into CMSMS .htaccess...

eg.:
http://mysite.com -> http://www.mysite.com
http://mysite.com/contact -> http://www.mysite.com/contact

I was trying to put:

Code: Select all

rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]
into the CMSMS .htaccess, but its not working.
My page works fine, and I have 'mod_rewrite' turned on in config.php

I was fighting with it for over 5 hours, and I didn't found solution...
Help me please!

My .htaccess:

Code: Select all

  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /
 
  # 301 Redirect all requests that don't contain a dot or trailing slash to
  # include a trailing slash
  # except for form POSTS
  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{REQUEST_URI} !\.
  RewriteCond %{REQUEST_METHOD} !POST$
  RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
 
  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Thank you, and sorry for english.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: "no www" -> "www" Redirect 301 problem

Post by Rolf »

Hello,

Perhaps some info here at point 3: http://forum.cmsmadesimple.org/viewtopic.php?t=36912

Grtz. Rolf
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
steelexus
New Member
New Member
Posts: 5
Joined: Wed May 25, 2011 3:07 pm

Re: "no www" -> "www" Redirect 301 problem

Post by steelexus »

Thank you so much!!! I love you.
The order of command was important in this case...

Here is my .htaccess now:

Code: Select all

  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /

  # Link to http://website.com then redirect to http://www.website.com
  RewriteCond %{HTTP_HOST} ^website\.com [NC]
  RewriteRule ^(.*)$ http://www.website.com/$1 [L,R=301]

  # 301 Redirect all requests that don't contain a dot or trailing slash to
  # include a trailing slash
  # except for form POSTS
  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{REQUEST_URI} !\.
  RewriteCond %{REQUEST_METHOD} !POST$
  RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
 
  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA]
Everything is working fine now :)
Thanks again.
Post Reply

Return to “The Lounge”