Reputation: 373
I have one domain: www.abc.com
I want to use Apache virtual host to get this:
www.abc.com/index.html?id=m1 ,www.abc.com/index.html?id=m2
to visit
/home/m/index.html
and
www.abc.com/index.html?id=a1 ,www.abc.com/index.html?id=a2
to visit
/home/a/index.html
Can I use apache regex to complete this without .htaccess, like this:
<VirtualHost (www.abc.me/*?id=a*):80>
DocumentRoot /var/www/html/laohu_v1
ServerName www.abc.me
ServerAlias www.abc.me/*?id=a*
</VirtualHost>
Upvotes: 0
Views: 1198
Reputation: 739
First, you only need or should use .htaccess when you don't have full access to your server. Vhost doesn't require to be put in .htaccess. Our Apache config uses none at all ;)
Here is how your vhost could look like. But if you only host one domain with entrance over one port on your server, leave out the <VirtualHost>
directive and put the rewrite directly in your server's config.
<VirtualHost *:80>
DocumentRoot /var/www/html/laohu_v1
ServerName abc.me
ServerAlias www.abc.me
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=(.*)\d$
RewriteRule ^(.*) /home/%1/index.html
</VirtualHost>
RewriteCond %{QUERY_STRING} ^id=(.*)\d$
change that to (.)
if only ONE character is in front of the digit. And if you need more than one digit, change that to: \d+
Upvotes: 1