Url Rewrite and Force www

Has anyone gotten the url rewrite to work with forcing your domain to use www?

My .htaccess looks like this for the url rewrite




RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php




Any help would be appreciated.

"Has anyone gotten the url rewrite to work with forcing your domain to use www?"

what do you mean by forcing domain to use www? what if testing in local environment the url will be www.localhost?

Please be more specific on what you have done and what fails and where, as Yii handles to perfection www.domain or domain. or even subdomai.domain. Maybe it is an issue on your server or on your development computer or…

Cheers

first of all if you are running apache2 on linux check mod-rewirte in ls -l /etc/apache2/mods-enabled/ and cat /etc/apache2/mods-enabled/rewrite.load to be compiled and enabled

secondly , check your default site configuratoin here : /etc/apache2/sites-available/default for ModRewrite enablility. ( AllowOverride All ).




RewriteCond %{HTTP_HOST}  ^yourdomain\.com

RewriteRule ^/(.*)$ http://www.yourdomain.com/$1 [R=301,L] 



would this go before the yii specific configuration?




RewriteEngine on


#Force www

RewriteCond %{HTTP_HOST}  ^yourdomain\.com

RewriteRule ^/(.*)$ http://www.yourdomain.com/$1 [R=301,L] 


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



Above solution is not working for me. Please help

Has anyone found a solution for this?

I have added the Rewrite like I have always done, but now it adds /public_html to the end of the URL and continues to do so. In other words, a loop.

I could not post this as it contains urls and it is one of my firsts posts, please review the image.

This is to force the opposite situation from www.[]com to []com