Apache2 - Redirecting a subdomain to another URL
44,584
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]
Related videos on Youtube
Author by
Technius
Updated on September 18, 2022Comments
-
Technius almost 2 years
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?
-
jww over 7 yearsTry adding the following to
.htaccess
in the parent directory above the directory of interest:RedirectMatch ^/foo/$ /foo/bar/
orRedirectMatch ^/foo/$ /bar/baz/
. Also see How to get apache2 to redirect to a subdirectory.
-
-
Technius about 11 yearsI 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?
-
Paschalis almost 10 yearsThis 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!
-
Golar Ramblar about 6 yearsHow to do ot to preserve
http://
orhttps://
, whatever wayb.website.com
was accessed in the first place?