Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

apache - Forward subdomain link to domain with same path

I want to forward all external links for my site that start with a subdomain, to the same path, but without the subdomain.

Ex. : https://mail.example.org/path1/file

To be: https://example.org/path1/file

I tried adding the following to .htaccess but it didn't work:

RewriteCond %{HTTP_HOST} ^mail.example.org$ [NC]
RewriteRule ^ https://example.org%{REQUEST_URI} [L,R]

I aslo tried RewriteRule ^(.*)$ https://example.org/$1 [L,P] but didn't work.

question from:https://stackoverflow.com/questions/65935760/forward-subdomain-link-to-domain-with-same-path

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create a wildcard subdomain for your domain, and add a virtualhost for it, if there is not a virtual host without ServerName:

<VirtualHost *:80>
DocumentRoot /path/to/an/example/documentroot
#make sure mod_rewrite is enabled
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.org$ [NC]
RewriteRule ^ https://example.org%{REQUEST_URI} [L,R]
</VirtualHost>

This will forward all subdomains without a separate VirtualHost.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...