Forum Moderators: phranque
I'm trying to use http.conf to do a permanent redirect from mysite.com to www.mysite.com. I can't use mod_rewrite in .htaccess because FrontPage chokes on it.
I have my own server with several websites, and in looking through the existing http.conf file, it shows a virtual host for the site, so I figured all I had to do was add this line in the virtual host section for the site in question:
PermanentRedirect / [mysite.com...]
But when I do that and restart Apache, all the other sites come back ok but mysite.com won't load. As soon as I take out the PermanentRedirect, it works. Is there something I'm missing? Thanks..
Here is the existing section in http.conf, the PermanentRedirect I tried was added after the "ServerAlias" line:
<VirtualHost 111.11.111.11>
ServerAdmin webmaster@mysite.com
DocumentRoot /home/mysite/public_html
BytesLog domlogs/mysite.com-bytes_log
ServerName www.mysite.com
User xyz
Group xyz
ServerAlias mysite.com www.mysite.com
CustomLog domlogs/mysite.com combined
ScriptAlias /cgi-bin/ /home/xyz/public_html/cgi-bin/
</VirtualHost>
Welcome to WebmasterWorld!
Yes, your code will redirect both mysite.com and www.mysite.com to www.mysite.com -- You've created a redirection loop. The client will be redirected until it (or the server) reaches its maximum redirection limit. You should see this error clearly stated in your server error log.
To solve this problem, you'll need to use mod_rewrite within a container (such as your existing <VirtualHost>) in httpd.conf.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Jim
I don't understand why the http.conf solution I tried doesn't work - it works perfectly for a friend of mine. Below is the code from http.conf that works on her site. When I try it, it doesn't work, the site in question will not load.
The way I understand it, the first VirtualHost statement sets up a virtual site called mysite.com and then redirects everything to www.mysite.com. The second virtual host has always been in the http.conf by default. Any hints on why this works on one server but not another?
<VirtualHost 11.11.111.11>
BytesLog domlogs/mysite.com-bytes_log
ServerName mysite.com
Redirect permanent / [mysite.com...] </VirtualHost>
<VirtualHost 11.11.111.11>
ServerAdmin root@mysite.com
DocumentRoot /home/mysite/public_html
BytesLog domlogs/mysite.com-bytes_log
ServerName www.mysite.com
User mysite
Group mysite
ServerAlias mysite.com www.mysite.com
CustomLog domlogs/mysite.com combined
ScriptAlias /cgi-bin/ /home/mysite/public_html/cgi-bin/
</VirtualHost>
I added this redirect (below) to the VirtualHost for my website that already exisited in my httpd.conf file. The redirect from "mysite.com" to "www.mysite.com" now works AND FrontPage has no problems with it:
<VirtualHost 111.11.111.11>
ServerAdmin me@mysite.com
DocumentRoot /home/mysite/public_html
BytesLog domlogs/mysite.com-bytes_log
ServerName www.mysite.com
User meandmy
Group meandmy
ServerAlias mysite.com www.mysite.com
CustomLog domlogs/mysite.com combined
ScriptAlias /cgi-bin/ /home/meandmy/public_html/cgi-bin/
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^/(.*) [mysite.com...] [R=301,L]
</VirtualHost>
Note that the ^/ before the (.*) eliminates the extra slash character, found this tip in another webmasterworld thread.
I tested this using one of the redirect test websites that checks to make sure the redirect works and that it is "search engine friendly" and it passed.
Thanks for the help and I hope this information will help someone else!