Simple Machines Community Forum

SMF Support => SMF 1.1.x Support => Topic started by: Carloswaldo on November 07, 2008, 05:02:12 PM

Title: Add "www" to url with .htaccess
Post by: Carloswaldo on November 07, 2008, 05:02:12 PM
I've been searching but I only found about how to erase the "www" from the url, but I need exactly the opposite, I need to add the "www" to the url.

This beacuse I've installed PrettyUrls mod, it works, but it renames the urls without the "www".

My htacces is this:

# Pretty URLs mod
# http://code.google.com/p/prettyurls/
# .htaccess file generated automatically on: November 7, 2008, 16:10

RewriteBase /foro
RewriteEngine on

# Rules for: topics
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]
Title: Re: Add "www" to url with .htaccess
Post by: D M G on November 07, 2008, 05:56:10 PM
# Rewrite to www.

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

That works for adding www. You just need to add your domain where it says example.com.
Title: Re: Add "www" to url with .htaccess
Post by: Sarge on December 03, 2008, 11:57:51 PM
Hello Carloswaldo, does the previous post help?
Title: Re: Add "www" to url with .htaccess
Post by: Carloswaldo on January 02, 2009, 01:54:36 PM
No, I try all the ways, but I couldnt, I finally give up and erase the www from all the urls.
Title: Re: Add "www" to url with .htaccess
Post by: Ol@v on June 09, 2011, 02:48:34 AM
I just had the same problem and found this topic.

At first it did't worked as told above, but if you just add one line on top of the file it all works out.

Just start the .htaccess with "RewriteEngine On"
As below, and don't forget to change "example" in your own domainname :)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Title: Re: Add "www" to url with .htaccess
Post by: MrPhil on June 09, 2011, 10:56:24 AM
Reply 1 probably didn't mention RewriteEngine On because the original post already had that line.

For SEO purposes it's good to be consistent with www. or without it, rather than having a mixture of the two. If an SEO/SEF mod is outputting only non-www URLs, that's usually OK, unless you have other reasons (such as an SSL certificate issued to www.) to insist on www. URLs. Any server will accept either form of a domain name (with or without www.).

If an SEO/SEF mod is outputting only non-www URLs, it won't do much good to change them in the .htaccess to the www form. Maybe that's why the OP gave up on it? If you want to see www. form links output by your forum, you need to modify the mod to use www. That should be easy enough to find where in the code URLs are built, and add www. to it. You might even have some point where you give the domain name, and you can just make it www.example.com instead of example.com. Settings.php?
Title: Re: Add "www" to url with .htaccess
Post by: desibees on August 06, 2011, 02:17:05 PM
Could someone please help me with 1 question?
I did exactly as it says and it even works, now. Do I need to go to my server settings and add www. there as well?
Example: When I go to server settings and look at my database URL, its mysitewhatever.com, should I change that to www.mysitewhatever.com as well?
Title: Re: Add "www" to url with .htaccess
Post by: MrPhil on August 06, 2011, 02:31:40 PM
If you are telling visitors/search engines/whoever to use www., it would be a good idea to practice what you preach and use repair_settings.php to change what's produced by your SMF to use www. At the least, responses will be quicker -- right now, when a visitor clicks on a link that says mysitewhatever.com, they have to make two round trips to the server:

     browser                                                                 server

     "mysitewhatever.com/some_page, please"  -->
                                                   <-- "use www.mysitewhatever.com"
     "www.mysitewhatever.com/some_page, please" -->
                                                                   <-- "here it is"
Title: Re: Add "www" to url with .htaccess
Post by: desibees on August 06, 2011, 08:27:07 PM
MrPhil,
Is there a way of adding www. in front of urls caused by "pretty urls"
There are trillion people asking this question but no one seems to know the answer.
Title: Re: Add "www" to url with .htaccess
Post by: MrPhil on August 07, 2011, 09:37:51 AM
First try repair_settings.php and change any domain name without www. to add it. I'm not familiar with using Pretty URLs, so beyond that you should ask on the support thread for that mod. I would guess that it uses whatever domain name you have defined in Settings.php (which repair_settings.php will change), but as I said, I'm not familiar with PU to say for sure.