CodeIgniter Forums
CodIgniter and htaccess rewrite rule question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CodIgniter and htaccess rewrite rule question (/showthread.php?tid=33904)



CodIgniter and htaccess rewrite rule question - El Forum - 09-12-2010

[eluser]felyx[/eluser]
Well I have the following htaccess file and it is working fine but I will explain below what my problem is.

Code:
RewriteEngine on
# RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?/$1 [L]

What my problem is that I want to redirect http://www.somesite.com to http://somesite.com without ruining my actually working htaccess file/website. Anyone can give me a little help how could I put this rewrite rule into my htacces file without causing trouble?
Thank you in advance!


CodIgniter and htaccess rewrite rule question - El Forum - 09-13-2010

[eluser]pickupman[/eluser]
Add this below RewriteEngine On
Code:
RewriteCond %{HTTP_HOST} !^www.somesite.com$ [NC]
RewriteRule ^(.*)$ http://www.somesite.com/$1 [L,R=301]



CodIgniter and htaccess rewrite rule question - El Forum - 09-13-2010

[eluser]felyx[/eluser]
[quote author="pickupman" date="1284403007"]Add this below RewriteEngine On
Code:
RewriteCond %{HTTP_HOST} !^www.somesite.com$ [NC]
RewriteRule ^(.*)$ http://www.somesite.com/$1 [L,R=301]
[/quote]

Thank youvery much it works!


CodIgniter and htaccess rewrite rule question - El Forum - 09-14-2010

[eluser]12vunion[/eluser]
Add a line below RewriteEngine on
Code:
#no WWW
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

The reverse also works
Code:
#Force WWW
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]