Glam Prestige Journal

Bright entertainment trends with youth appeal.

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 ^(.*)$ [L]

...but it does not work.

Is there a way to make it work?

1

2 Answers

You could always use a simple VirtualHost:

<VirtualHost *:80> ServerName b.website.com RedirectPermanent /
</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 ^(.*)$ [L]
3

Complementing the main answer

Redirect type

You can explicitly specify the type of redirect you pretend.
I suggest you use a temporary redirect (302) while testing the redirection rule.

# In a VirtualHost file
...
Redirect [301|302] /old_location
# In a .httaccess file
...
RewriteRule ^(.*)$ [R=302,L]

Specify directory matching patterns

You could only redirect requests that match some pattern.

# In a VirtualHost file
...
RedirectMatch [301|302] ^/public/(.*)$
# In a .httaccess file
...
RewriteRule ^/public/(.*)$ [R=302,L]

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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