.htaccess Redirect Subdomain to External URL

大城市里の小女人 提交于 2019-11-27 17:52:56

问题


We need to run a few subdomains from our main site and we need to point these to external sites that deal with the admin required.

I simply need to redirect a subdomain to an external URL using .htaccess and also any advise about where to put it in the .htaccess file e.g. right at the top, as i know this effects certain rewrite rules.

I won't write what i think it should be as this just leads the answer down a specific route.

Cheers Guys,

Really appreciate it.

Dan


回答1:


If you are redirecting a subdomain to another domain then there shouldn't be anything else in the .htaccess file other than this.

 # This will redirect a subdomain to another domain
 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^yoursubdomain\.yourdomain\.com$ [NC]
 RewriteRule ^(.*) http://www.newdomain.com/$1 [L,R]



回答2:


Here's the code I used and it worked for me:

# BEGIN CUSTOM Redirects
# This will redirect a subdomain to another domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^pw\.example\.com$ [NC]
RewriteRule ^(.*) https://www.example.com [L,R



回答3:


I tried both options but didn't work until I remove the $ and [L,R] this is the code that worked for me

 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
 RewriteRule ^(.*) http://newdomain.com.ar/?param=data&uparam2=data

hope it helps.



来源:https://stackoverflow.com/questions/13989162/htaccess-redirect-subdomain-to-external-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!