.htaccess rewrite rules for www.example.com and example.com -> this.example.com
I would lik开发者_运维知识库e my site to direct all traffic from www.example.com and example.com or anythingelse.example.com to this.example.com This is what I have in my .htaccess file which is located in /www/example.com/public_html directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://this.example.com/ [R=301,L]
It works when I visit this.example.com but when I visit http://example.com it redirects me to example.com/public_html and www.example.com doesn't redirect at all! However this.example.com works. This is my virtual host setting:
<VirtualHost 12.34.56.78:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias this.example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>
I've noticed in my error log when I visit: example.com it says "File does not exist: /srv/www/example.com/public_html/public_html"
Solution provided by requinix on devshed
RewriteEngine On
RewriteCond %{HTTP_HOST} !this.example.com
RewriteRule ^ http://this.example.com%{REQUEST_URI} [L]
精彩评论