I currently have a couple of "shortcut" subdomains (since some users seem to remember a subdomain more easily than an URL). I currently do this in the following way:
<VirtualHost *:80>
ServerName redirects.domain.com
ServerAlias *.domain.com
RewriteEngine On
# Option 1
RewriteCond %{HTTP_HOST} ^option1\.domain\.com$
RewriteRule ^.*$ http://www.domain.com/option1%{REQUEST_URI} [R=301,L]
# Option 2
RewriteCond %{HTTP_HOST} ^option2\.domain\.com$
RewriteRule ^.*$ http://www.domain.开发者_运维知识库com/option2%{REQUEST_URI} [R=301,L]
</VirtualHost>
This is the last entry in my sites-enabled folder so it won't interfere with other "real" subdomain definitions.
I have 2 questions:
- Could there be a general rule that just appends the subdomain part of the HTTP_HOST after domain.com/, so that 1 general rule is enough?
- If such a rule exists, is there still a way I can define the valid subdomains that may be redirected? (i.e. with an array-like structure)
# General Option
RewriteCond %{HTTP_HOST} ^(option1|option2)\.domain\.com$
RewriteRule ^.*$ http://www.domain.com/%1%{REQUEST_URI} [R=301,L]
精彩评论