Welcome Guest, Not a member yet? Register   Sign In
Force www. included in URL
#1

[eluser]iive[/eluser]
Hi, I would like to make sure all request to my site is in www.mysite.com instead of mysite.com. I do not know how to configure my .htaccess file to do that.

I have googled it a bit and I got a solution for that.. but it doesn't work properly if I combined it with my current .htacess file which hide the index.php from the URL.


.htaccess that force www in the url
Code:
RewriteCond %{HTTP_HOST} !^www.mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]

.htaccess that hide index.php from url
Code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !(.jpg|.gif|.png|.swf|.css|.js|.txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Anyone can help? I am not very good in apache. Sorry.
#2

[eluser]gon[/eluser]
To hide index.php from url, you can do what is said in the docs:

http://ellislab.com/codeigniter/user-gui.../urls.html
#3

[eluser]johnwbaxter[/eluser]
This is mine which does just that. I wont pretend to know what any of it means but it does work!

RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=301,L]

Hope it works for you!
#4

[eluser]iive[/eluser]
After I searched around,this is solution that I found which hide index.php from url and append www. for every request to the server. I hope it helps someone who want to have both features.

Code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteCond $1 !(.jpg|.gif|.png|.swf|.css|.js|.txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

It is not written by me, I just combine these codes together here.




Theme © iAndrew 2016 - Forum software by © MyBB