Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two subdomains, a.website.com and b.website.com, pointing to the same IP address. I want to redirect b.website.com to a.website.com:8080. I have this in my .htaccess file...

RewriteEngine on
RewriteCond {HTTP_HOST} b\.website\.com
RewriteRule ^(.*)$ http://b.website.com:8080$1 [L]

...but it does not work.

Is there a way to make it work?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You could always use a simple VirtualHost:

<VirtualHost *:80>
  ServerName b.website.com
  RedirectPermanent / http://a.website.com:8080/
</VirtualHost>

If you prefer to go with the .htaccess file, you're just missing a % sign on the Rewrite Condition:

RewriteEngine on
RewriteCond %{HTTP_HOST} b.website.com
RewriteRule ^(.*)$ http://a.website.com:8080$1 [L]
share|improve this answer
    
I tried both and they didn't work. I have mod_rewrite enabled and I have the VirtualHost in a separate site file. Is there anything that I'm missing? –  Technius May 21 '13 at 5:16
    
This works fine. I had a loop redirect problem, because I was pointing a subdomain to a subfolder, and that subfolder was redirecting. Now, I redirect the subdomain to the URL that corresponds to the folder, and the 2nd redirection happens just fine! –  Paschalis Jul 12 at 9:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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