Home .htaccess: Rewrite domains to subdirectories automatically
Reply: 0

.htaccess: Rewrite domains to subdirectories automatically

Jonny
1#
Jonny Published in 2017-11-14 15:56:59Z

I have this directory structure:

/default/...
/www.example.com/...
/www.anotherone.net/...
/.htaccess

My goals:

  1. I want to map every request automatically to the corresponding subdirectory of the requested hostname. Example: www.mysite.com will be served from the subdirectory with the same name.
  2. If a domain is requested, that is not represented by a subdirectory, the domain shall be served from the "default" subdirectory. Example: There is no directory /www.newsite.info, therefore it will be served from /default.
  3. It shall not be possible to request http://www.example.com/www.anotherone.net or http://www.example.com/default.

I'm having problems with goal #3, because that's what possible at the moment.

That's my .htaccess at the moment:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} -d
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [L,NS]

RewriteCond %{HTTP_HOST} !-d
RewriteRule ^(.*)$ default/$1 [L,NS]

What should I add, to deny requests like http://www.example.com/www.anotherone.net or http://www.anotherone.net/default?

Unfortunately it's not possible to solve the problem via virtual hosts oder httpd.conf.

Thanks in advance

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.544992 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO