CodeIgniter Forums
Force www? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Force www? (/showthread.php?tid=42570)



Force www? - El Forum - 06-10-2011

[eluser]robustus[/eluser]
This is probably a silly question, but how do I force codeigniter to make sure the "www" subdomain is present in the url string? For example, if the user types "mydomain.com", I want that to resolve as "www.mydomain.com". ... I'm using ajax via jquery and apparently the subdomain has to match exactly in order for it to work.

Is this something that's done on the CI level, or do I have to use .htaccess or something?


Force www? - El Forum - 06-11-2011

[eluser]InsiteFX[/eluser]
.htaccess tips and tricks

InsiteFX


Force www? - El Forum - 06-11-2011

[eluser]mahni1390[/eluser]
:question: :exclaim:

you can use .htaccess. to solve it

[url="http://www.parscanada.com"]مهاجرت به کانادا[/url]


Force www? - El Forum - 06-13-2011

[eluser]robustus[/eluser]
And to actually be complete in response, here's what solved it:

Below is the root .htaccess file, and I have the base_url set to "http://www.mydomain.com/" in my CI config.


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

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]