I have these Rewrites, but I would like to have the URL stay the same as what is typed originally, I thought removing the [R] flags would stop it but it hasn't

RewriteCond %{HTTP_HOST} ^examplea\.example\.com$ [NC]
RewriteRule (.*) http://examplea.example.com:32400/web [L]

RewriteCond %{HTTP_HOST} ^exampleb\.example\.com$ [NC]
RewriteRule (.*) http://exampleb.example.com:9091 [L]

Edit: would this work better?

RewriteCond %{HTTP_HOST} ^hello.example.com$ 
RewriteRule ^(/)?$ welcome [L]
  • 1
    It will always trigger an external redirect if you specify a different port, regardless of whether you explicitly state it is a Redirect or not. However, you can get around this with mod_proxy. See this answer on SO: stackoverflow.com/questions/9308088/… – MrWhite Apr 24 '14 at 19:21
  • 1
    I like using mod_proxy. Just use caution to secure your mod_proxy before enabling. Otherwise, it will not take long before the Chinese begin to send many 100K's requests per hour to your site. – closetnoc Apr 24 '14 at 20:15
  • ahh okay, how do you secure your mod proxy? – user38100 Apr 24 '14 at 21:27

It looks to me like you would are trying to fetch data from a web service that is running on another port and display it using your main web server.

mod_rewrite can be configured to do so. You have to have mod_proxy enabled and use [P] with your rewrite rules. Your directives might look like this:

RewriteEngine  on

RewriteCond %{HTTP_HOST} ^examplea\.example\.com$ [NC]
RewriteRule (.*) http://examplea.example.com:32400/web/$1 [P,L]
ProxyPassReverse / http://examplea.example.com/

RewriteCond %{HTTP_HOST} ^exampleb\.example\.com$ [NC]
RewriteRule (.*) http://exampleb.example.com:9091/$1 [P,L]
ProxyPassReverse / http://exampleb.example.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.