Virtual host conf file redirect adds local file path
I'm adding the following rewrite to the conf file for my virtual host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
.... A bunch of aliases here
The site works fine with the www. but if you enter the domain without the www. the site will be redirected to www.example.com/home/example/public_html - it adds the file path. How can I prevent this?
Here's the aliases:
Alias /index.php /home/cms/public/index.php
Alias /skins/admin /home/c开发者_JS百科ms/public/skins/admin
AliasMatch ^/scripts/(\w+)/admin/(\w+)\.js /home/cms/modules/$1/scripts/admin/$2.js
AliasMatch ^/scripts/(\w+)/(\w+)\.js /home/cms/modules/$1/scripts/$2.js
Alias /scripts /home/cms/public/scripts
AliasMatch (?i)^/flash/([A-Za-z]*)/([A-Za-z_]*).swf$ /home/cms/public/flash/$1/$2.swf
Alias /css /home/cms/public/css
Alias /thirdparty /home/cms/public/thirdparty
RewriteEngine off
<Directory /home/cms>
Order allow,deny
Allow from all
</Directory>
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
</Location>
According to documentation, you should have the local path in the regex, before the grouping:
RewriteRule ^\/home\/example(.*) http://www.example.com$1 [R=301,L]
Also according to the docs:
On the first RewriteRule [the Pattern] is applied to the (%-decoded) URL-path of the request; subsequent patterns are applied to the output of the last matched RewriteRule.
This would suggest you have other RewriteRules prior to that one.
精彩评论