.htaccess non-www to www

yoghurtfarmer

Well-known member
Noticed my rewrite rule is no longer working and would like some help in fixing it :). Does it have anything to do with the L flag?

Please and thanks.

Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data|js|styles|install) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

RewriteCond %{HTTP_HOST} ^url\.com$ [NC]
RewriteRule ^(.*)$ http://www.url.com/$1 [R=301,L]
 
Any custom rewrite & redirect rules need to be placed before xenforo's rewrite rules.
Try this:
Code:
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data|js|styles|install) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
 
Thanks for the suggestion, when I tried it earlier it redirected to the wrong url though.

eg: http://url.com/threads/title.1/ would go to http://url.com/index.php/title.1/

Figured out it was the trailing dollar sign that was screwing it up, I don't even know why it's there... never noticed because the redirection worked fine in SMF.

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

I removed the $ and it works fine now :). Thanks for the help everyone.

So if anyone else is stuck, copy the following and place it immediately after RewriteEngine On and before the Xenforo rewrites.

RewriteCond %{HTTP_HOST} ^url\.com [NC]
RewriteRule ^(.*)$ http://www.url.com/$1 [R=301,L]
 
I think unless you have subdomains, the www is unnecessary.

The bigger issue is cookie issues when some people visit your website from www. and some don't. So just for cookie reasons, enforcing either www. or no www. is a good idea.
 
What's the fascination/craze with removing www. from URLs now?

Is it just to be different? For neatness?

http://no-www.org/

I favour the www though ;), just looks more balanced to me. Redirects keep everything consistent so you don't end up with two different URLs pointing to the same content. The www and non-www URLs are also indexed separately unless you have redirected them or set a preference in Google Webmaster Tools.

http://www.www.extra-www.org/
http://www.yes-www.org/
 
I haven't even typed 'www' in the address bar for about 5 years now. It's just not necessary anymore. As for having it in the URL, I stopped doing that about 3 years ago. The link that cheeseshredder posted above explains it all.
 
I do have a rewrite rule so that it always shows "www".
Because XF-software logged me out when being on the domain including "www" and then entered the domain without "www", so saying I got logged out from the website by just removing the "www" from the URL I typed into my browser....... strange
 
What's the fascination/craze with removing www. from URLs now?

Is it just to be different? For neatness?


It's like Internet Explorer 6 and vBulletin -> outdated.

We're in a world now where every 1 year old has an iPad or whatever, and I think by now we can assume people know they're on the Internet and now at gopher or a subdomain.

Analogue people say: I am on the Facebook
10 years ago that was: I am on double you double you double you dot come Facebook

Now they all tweet: I am on Facebook and I google, brb, tweeting, ehl oh elh.
 
Top Bottom