autumnfall autumnfall - 1 month ago 16
Apache Configuration Question

I would like to redirect the domain name to the server subdirectory

I would like to redirect the domain name to the server subdirectory by using apache rewrite rules .How could I change the .htaccess file?

www.a.com bound to /a

www.b.com bound to /b

I could not change httpd-vhosts.conf because some Cross-domain issues.

The /d has a .htaccess file ,i would caught the 404 error if i deleted it,or I would caught the ERR_TOO_MANY_REDIRECTS .

The .htaccess file:



<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>







Answer

Here it is: (save as .htaccess on your website's root)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)\.com$
RewriteRule ^(.*)$ /full/path/to/document/root/%1/$1 [END]

Website root, is the DocumentRoot defined on your apache2/vHost config. You said you want www.a.com redirects to /a, DocumentRoot is the full system path to URL path /

This will work on Apache 2.4, NOT 2.2.

Reply to the first comment:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(a|b|c).com$
RewriteRule ^(.*)$ /full/path/to/document/root/d/$1 [END]
RewriteCond %{HTTP_HOST} ^www.(.*)\.com$
RewriteRule ^(.*)$ /full/path/to/document/root/%1/$1 [END]