mod_rewrite redirect subdomain to folder
Posted
by
kitensei
on Server Fault
See other posts from Server Fault
or by kitensei
Published on 2012-11-16T09:19:39Z
Indexed on
2012/11/16
11:03 UTC
Read the original article
Hit count: 225
I have a wordpress blog at the url http://www.orpheecole.com, I would like to setup 3 subdomains (cycle1, cycle2, cycle3) being redirected to their folders (1 subdomain = 1 wp blog, no multisite enabled)
The file tree looks like this:
/var/www/orpheecole.com/
/var/www/cycle1.orpheecole.com/
/var/www/cycle2.orpheecole.com/
/var/www/cycle3.orpheecole.com/
the following .htaccess try to redirect to /var/www/orpheecole.com/cycleX instead of its own directory, but id it's possible i'd rather redirect every subdomain to its own www folder. my sites-enabled file for main site is
# blog orpheecole
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName orpheecole.com
ServerAlias *.orpheecole.com
DocumentRoot /var/www/orpheecole.com/
<Directory /var/www/orpheecole.com/>
Options -Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/orpheecole.com-error_log
TransferLog /var/log/apache2/orpheecole.com-access_log
</VirtualHost>
and the .htaccess located on /var/www/orpheecole.com/ looks like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.orpheecole\.com$
RewriteCond /var/www/orpheecole.com/%1 -d
RewriteRule ^(.*) www\.orpheecole\.com/%1/$1 [L]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
I tried to remove wordpress directives but nothing change, and the rewrite mod is enabled and working.
© Server Fault or respective owner