开发者

Apache Virtual Host Redirect: *.example.com to www.example.com

开发者 https://www.devze.com 2023-02-19 22:23 出处:网络
I\'m simply trying to redirect any example.com to www.example.com. The redirect currently sends example.com to www.example.com//.

I'm simply trying to redirect any example.com to www.example.com. The redirect currently sends example.com to www.example.com//.

The following code is in my virtual host configuration file:

RewriteCond %{HTTP_HOST} ^suksanvillas\.com$ [NC]
        RewriteRule 开发者_如何学C^(.*)$ http://www.suksanvillas.com/$1 [R=301,L]

This seems to be what all the tutorials suggest, but I'm unable to understand how I'm picking up the extra "/" on the redirect. Any help on even where I might look is appreciated.

PS: Other subdomains, for examples "guides.examples.com" should not be redirected.

Thanks.


Avoid capturing the leading slash by using "^/" in the beginning of the pattern:

RewriteRule ^/(.*)$ ...

With that small change everything should work great.

0

精彩评论

暂无评论...
验证码 换一张
取 消