Add "www" to url with .htaccess

Started by Carloswaldo, November 07, 2008, 05:02:12 PM

Previous topic - Next topic

Carloswaldo

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]

D M G

# 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.

Sarge

Hello Carloswaldo, does the previous post help?

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Carloswaldo

No, I try all the ways, but I couldnt, I finally give up and erase the www from all the urls.

Ol@v

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]

MrPhil

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?

desibees

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?


I'm the.. Help abuser


MrPhil

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"

desibees

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.


I'm the.. Help abuser


MrPhil

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.

Advertisement: