开发者

.htaccess subdomain redirect problem

开发者 https://www.devze.com 2023-02-01 18:04 出处:网络
I have a website let\'s say www.example.com and I have a subdomain something.example.com Both main domain and sub domain are pointing to directory \"public_html\"

I have a website let's say www.example.com and I have a subdomain something.example.com

Both main domain and sub domain are pointing to directory "public_html"

I have .htaccess on root which redirects any URL without www to www. For e.g. if user enters example.com then he will be redirected to www.example.com If user enters example.com/mypage.html then he will be redirected to www.example.com/mypage.html

Now the problem is this is also affecting my subdomain. Because if someone enters something.example.com/visit.html then he is redirect to www.example.com/visit.html

I don't want this! If user enters subdomain then I don't want to redirected to www domain. This is what I have in my .htacces file

RewriteCond %{HTTP_HOS开发者_C百科T} !^www.stackoverflow.com$ [NC]
RewriteRule ^(.*)$ http://www.stackoverflow.com/$1 [R=301,L]

Can you please tell me what should I do to solve above problem?

Thanks.


Do you have access to your webserver configuration? This is better done by configuring the webserver.

On apache you would configure one virtual domain like this:

<VirtualHost *:80>

        ServerName somedomainiwanttoredirect.com
        ServerAlias maybe.somemoredomainstoredirect.com
        ServerAlias orsubdomains.toredirect.com
        RewriteEngine On
        RewriteRule ^(.*)$ http://www.target.com/$1 [R=301,L]

</VirtualHost>

and on your real configuration, the www.target.com you add your subdomains that you do not want to be redirected: ServerAlias subdomain.target.com

0

精彩评论

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