| Linode Forum https://forum.linode.com/ |
|
| Automatically add www in front of domain name https://forum.linode.com/viewtopic.php?f=19&t=5217 |
Page 1 of 1 |
| Author: | thehcdreamer [ Thu Feb 18, 2010 4:33 pm ] |
| Post subject: | Automatically add www in front of domain name |
Hello, for a specific website I want to automatically add www in front of the domain name. Right now it works both with www and without. I'm not sure if I have to do this on the apache side, or dns, or somewhere else. Thanks in advance for your help. |
|
| Author: | shah [ Thu Feb 18, 2010 4:41 pm ] |
| Post subject: | |
You need a rewrite rule in your .htaccess file. Something along the lines of: Code: Options +FollowSymLinks |
|
| Author: | spearson [ Thu Feb 18, 2010 9:08 pm ] |
| Post subject: | |
That also requires the module mod_rewrite to be loaded (it usually is with a clean install of apache). |
|
| Author: | BarkerJr [ Fri Feb 19, 2010 8:03 am ] |
| Post subject: | |
Probably the cleanest way is to create separate vhosts for with and without www. One would simply contain a ServerName and a Redirect Permanent clause. |
|
| Author: | thehcdreamer [ Fri Feb 19, 2010 9:13 am ] |
| Post subject: | |
BarkerJr wrote: Probably the cleanest way is to create separate vhosts for with and without www. One would simply contain a ServerName and a Redirect Permanent clause.
I'd like to try the vhost option. This is what I currently have: Code: <VirtualHost *:80> Could you please help me to figure out how to change that only for the www, and what to put inside another virtual host just for the redirect? Thanks |
|
| Author: | rsk [ Fri Feb 19, 2010 11:53 am ] |
| Post subject: | |
Code: <VirtualHost *:80> You'll need mod_alias enabled for Redirect calls. It is typically on in default configurations. PS. I, personally, prefer doing it other way around, automatically cutting the www. from hostname. It's annoying, and unnecessarily increases the size of URL. But hey, however you prefer. |
|
| Author: | kali25 [ Fri Feb 19, 2010 11:57 am ] |
| Post subject: | How I solve the problem |
Here is how I do it. I omitted all the other directives for clarity. But the Redirect Virtualhost block is all inclusive, no logging just the redirect. What is nice about this redirect is it works for any page. So if the visitor goes to example.com/mydir/mypage.html, it will be redirected to www.example.com/mydir/mypage.html Code: ## www.example.com Edit: I see I just posted about the same response as above. For work I redirect to www because that is how my company displays our websites on print ads, tv, and such, but for personal sites I redirect to non-www since www is not necessary, but it is nice to have www for the Ctrl-Enter crowd. |
|
| Author: | rsk [ Fri Feb 19, 2010 12:11 pm ] |
| Post subject: | |
Actually, your post reminded me of something: as the first vhost entry is being chosen when there's no Host: header present, the config as I put it would end up in a redirect loop if the client is HTTP/1.0 or simply non-compliant and doesn't supply it. Your way of putting the redirecting vhost after the main one makes it less likely to happen. (Of course, in a multidomain vhost setup, the default vhost should be an error/information page... but in any case, having a redirect in the default isn't a good idea.) Edited my post accordingly, swapping the blocks. |
|
| Author: | thehcdreamer [ Fri Feb 19, 2010 1:17 pm ] |
| Post subject: | |
rsk wrote: Actually, your post reminded me of something: as the first vhost entry is being chosen when there's no Host: header present, the config as I put it would end up in a redirect loop if the client is HTTP/1.0 or simply non-compliant and doesn't supply it.
Your way of putting the redirecting vhost after the main one makes it less likely to happen. (Of course, in a multidomain vhost setup, the default vhost should be an error/information page... but in any case, having a redirect in the default isn't a good idea.) Edited my post accordingly, swapping the blocks. Thanks rsk, to reply to your question. I prefer to use the www for that specific site. Usually I do the other way around too. Thanks again, also thanks to kali25. |
|
| Author: | hieuvo [ Wed May 09, 2012 3:12 pm ] |
| Post subject: | |
I have the same problem, currently when people access to www.example.com, they will be redirected to example.com automatically. But now I want to reverse it, when people come to example.com, they should be directed to www.example.com. When I try to rewrite the url by .htaccess or change the VirtualHost file, It will lead to Loop direct error. I spent hours to figure out it, but I cannot find a solution for this issue. |
|
| Author: | Dweeber [ Wed May 09, 2012 5:36 pm ] |
| Post subject: | |
Hard to provide any possible help there without some details of what you are doing to give a possible fix. I prefer the mod_rewrite method myself rather doing it in the virtual hosts configuration. No server reload needed and you can provide a Perm redirect 301 code with it. |
|
| Author: | hieuvo [ Wed May 09, 2012 8:45 pm ] |
| Post subject: | |
Fortunately, I figured it out. The problem is cause by redirecting mechanism of wordpress. Just change the address in setting of wordpress, the problem is fixed. |
|
| Page 1 of 1 | All times are UTC-04:00 |
| Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |
|