Welcome Guest, Not a member yet? Register   Sign In
Redirecting www to non-www
#1

[eluser]alexbet[/eluser]
Hi All,

I did a CI aplication for a client which works fine. But, he also requested that I tweak the htaccess file for the www.domain.com to redirect to domain.com (without the "www" part). I tried many different things, but none would work with the CI application..

Does anyone know how to do this and still keep the CI application working properly? Any help is greatly appreciated. Thanks!

Alex
#2

[eluser]CroNiX[/eluser]
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^yoursite.com$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

Make sure to change you base_url in your config.
#3

[eluser]alexbet[/eluser]
Hey CroNiX,

This works great, except for one small thing. When I type in the domain as www.domain.com and when I am redirected to the non-www domain, the URL in the address bar becomes the following:

http://domain.com/index.php/

Is there any way to take avoid having the "index.php" part in the URL when you are redirected? Here is what I have now in the htaccess file:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^domain.com$
RewriteRule (.*) http://domain.com/$1 [R=301,L]

Thanks SO much! Smile
Alex
#4

[eluser]CroNiX[/eluser]
try putting the non-www rules at the top above the index rules.
#5

[eluser]alexbet[/eluser]
AWESOME!!! Works just fine!

Thank you VERY MUCH CroNiX!!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB