1

So I got my htaccess file set up, it look like this:

Options +FollowSymLinks

RewriteEngine on

RewriteBase /

# MAGIC
RewriteCond $1 !/$
RewriteCond $1 !\.
RewriteRule ^(.+)$ /$1/ [R=301,L]
# //MAGIC

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.domain\.com
RewriteCond %{REQUEST_URI} !^/subdomains/
RewriteRule ^(.*)$ /subdomains/%1/$1 [P,NC,QSA]

I work quite fine, it nicely directs phpmyadmin.domain.com to phpmyadmin.domain.com/subdomains/phpmyadmin/

But I think it is quite ugly it shows that in the url. So I want it to redirect it silently so it still points to phpmyadmin.domain.com/subdomains/phpmyadmin/ but the client can only see phpmyadmin.domain.com

I've been looking around but I couldn't find anything that worked like I wanted it to work. Does anyone have an idea how to fix this?

1 Answer 1

0

You're working too hard. Try using the VirtualDocumentRoot with a variable. %1 will use the first part of the domain, or %-3 will use the third to last part (both represents the same for your case). You'll need to enable the module mod_vhost_alias for this to work.

<VirtualHost *:80>
  VirtualDocumentRoot /var/www/%1
  ServerName www.domain.com
  ServerAlias *.domain.com
</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .