htaccess subdomain redirect to port while keeping original url

。_饼干妹妹 提交于 2019-12-13 18:07:17

问题


I have trouble getting this to work properly, what I'm trying to do is make http://subdomain.domain.com redirect to domain.com:8080 while keeping the original url "subdomain.domain.com"

Code so far:

RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteRule ^(.*)$ http://%1domain.com:8080$1 [L]

Which does the redirect, but browser url changes to "http://domain.com:8080" which is not what I seek.

Thank you in advance!


回答1:


For this to happen you need to enable mod_proxy in subdomain\.domain\.com. Once it is enabled try this rule in DocumentRoot/.htaccess of subdomain.domain.com:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain\.(domain\.com)$
RewriteRule ^ http://%1:8080%{REQUEST_URI} [L,NE,P]


来源:https://stackoverflow.com/questions/20721377/htaccess-subdomain-redirect-to-port-while-keeping-original-url

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