问题
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