0

I have an Apache server running ISPConfig. On a domain example.com I am pointing its subdomains to subfolders, e.g. foo.example.com to /sub/foo. This works fine:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]

Now I need to point one specific subdomain into a subfolder's subfolder (bar.example.com into /sub/bar/public to use Laravel). But for some reason, this does not work:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^bar\.example\.com/
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]

RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]
Ian Pollak
  • 83
  • 11
  • 1
    why not use virtual host? – Muhammad Dyas Yaskur Oct 23 '20 at 03:34
  • @MuhammadDyasYaskur I could do that but I'm trying to do it using ISPconfig without any "hacking" on the side. I know adding a vhost is not hacking of Apache but it is going around ISPconfig. The code above is put in a "Apache directives" field in the ISPconfig administration of this domain. – Ian Pollak Oct 23 '20 at 03:47

1 Answers1

0

The problem was the / at the end of the domain name. If I delete it or put there $, it works.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^bar\.example\.com$
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]

RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]
Ian Pollak
  • 83
  • 11