apache config help needed

  • sergey
  • Born
  • Born
  • sergey
  • Posts: 2

Post 3+ Months Ago

Hi all!
i need to setup a virtual host so that if someone hits http://mydomain.com he redirected to http://www.mydomain.com.

i did this before on other machine with

Code: [ Select ]
  
Servername www.mydomain.com
ServerAlias mydomain.com
  1.   
  2. Servername www.mydomain.com
  3. ServerAlias mydomain.com


in VirtualHost directive and


Code: [ Select ]
RewriteEngine On
ErrorDocument 404 /404.html

# Non-canonical hosts? 301 please.
RewriteCond %{HTTP_HOST}  !^www [NC]
RewriteRule ^(.*)$     http://www.mydomain.com/$1 [R=301,L]
  1. RewriteEngine On
  2. ErrorDocument 404 /404.html
  3. # Non-canonical hosts? 301 please.
  4. RewriteCond %{HTTP_HOST}  !^www [NC]
  5. RewriteRule ^(.*)$     http://www.mydomain.com/$1 [R=301,L]


in .htaccess

I did this on my new server, but the redirect doesn't work. What can the cause?
Thank you.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Code: [ Select ]
<VirtualHost *:80>
 ServerName mydomain.com
 Redirect / http://www.mydomain.com/
</VirtualHost>
  1. <VirtualHost *:80>
  2.  ServerName mydomain.com
  3.  Redirect / http://www.mydomain.com/
  4. </VirtualHost>

This is the best way to do it as it rewrites the user's URL to the proper address. It's also cleaner than using a rewrite. Though it doesn't send a 301, it shouldn't make all that much difference as user's aren't going to be bookmarking your non-www site.
  • sergey
  • Born
  • Born
  • sergey
  • Posts: 2

Post 3+ Months Ago

this213 wrote:
Code: [ Select ]
<VirtualHost *:80>
 ServerName mydomain.com
 Redirect / http://www.mydomain.com/
</VirtualHost>
  1. <VirtualHost *:80>
  2.  ServerName mydomain.com
  3.  Redirect / http://www.mydomain.com/
  4. </VirtualHost>

This is the best way to do it as it rewrites the user's URL to the proper address. It's also cleaner than using a rewrite. Though it doesn't send a 301, it shouldn't make all that much difference as user's aren't going to be bookmarking your non-www site.


Thanks for suggestion, but this does not works for me at all - i get 404.
It seems like something wrong with my httpd.conf
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Did you restart the server (stupid question, but figured I'd ask). I do this to all of my domains without issue on apache 1 and 2.

Make sure you've removed the rewrite rules.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 60 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.