apache - Remap request to different local path -


i'd serve multiple subdomains webserver:

example.com
projects.example.com
blog.example.com
wiki.example.com
...

the document root being set follows:

servername   example.com serveralias   *.example.com virtualdocumentroot "/var/www/%0/public" 

this works automatically sets document root corresponding subdomain. next requirement however, should detect if public folder in document root exists, , if not, serve file 1 directory earlier.

most of applications written laravel, come public folder, want create new script doesn't have public or deploy external software doesn't.

therefore document root example.com (which serves static index.html , style.css) should /var/www/example.com/ rather /var/www/example.com/public. tried via rewrite rules:

<if "!-d '/var/www/' . %{http_host} . '/public'">     rewriteengine on     rewriterule ^ "/var/www/%{http_host}" [l,qsa] </if> 

this result of rewrite error log:

[rewrite:trace2] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] init rewrite engine requested uri / [rewrite:trace1] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] pass through / [rewrite:trace3] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] [perdir *if/] add path info postfix: /var/www/example.com -> /var/www/example.com/public/ [rewrite:trace3] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] [perdir *if/] applying pattern '^' uri '/var/www/example.com/public/' [rewrite:trace2] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] [perdir *if/] rewrite '/var/www/example.com/public/' -> '/var/www/example.com' [rewrite:trace1] [pid 32153] mod_rewrite.c(475): [client 62.159.226.12:27139] 62.159.226.12 - - [example.com/sid#7f6588016340][rid#7f6587f810a0/initial] [perdir *if/] initial url equal rewritten url: /var/www/example.com [ignoring rewrite] 

as can see, maps correctly, reason doesn't serve file there (i assume it's because doesn't append index.html or like).

how around this?

it's because core sees non-existent public/ , splits out of current filename , path_info. [dpi] flag won't here because removes path_info @ last minute side-effect of rewrite.

unfortunately change try ditch path_info caught in "loop detection" of mod_rewrite , mistaken no change in filename.

you should invert logic there never stray path_info injected. rewrite optionally add public suffix instead of removing it.

this allows drop negation , entire using typical -d test in rewritecond.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -