Httpd rewrite rule with another DocumentRoot dir

Is there a way to make a rewrite rule for a file located in a path other than DocumentRoot? Let's say I have a domain http: //test.ldt/ with DocumentRoot / home / test_ltd /, and I want when the file is requested under static. subdomain ( http: //stats.test.ldt/ ) it will look for the requested file from another path, for example / home / static _files /

I was recommended to use mod_alias. However, I'm not sure how to make it work when I need it with a subdomain.

in cristis:

You're not right. For example, if these are my httpd rules:

ServerName domain.ltd
ServerAlias www.domain.ltd

DocumentRoot /home/domain_ltd

RewriteEngine on

RewriteCond %{HTTP_HOST} static2.domain.ltd
RewriteRule (.*)$ /home/static_files/$1 [L]

DirectoryIndex index.html index.htm index.php

And the client will request the file static2.domain.ltd/foo.txt, the file will search in / home / domain_ltd / home / static_files / $ 1

+3
2

VirtualHost, DocumentRoot, , ( , -, ServerFault ...)

:.

<VirtualHost *:80>
    ServerName static.domain.tld

    DocumentRoot /home/static_files/

    <Directory /home/static_files>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

mod_alias mod_rewrite, . - ...

httpd.conf:

Alias /static /home/static_files

.htaccess ( httpd.conf Directory /home/domain_tld):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^static
RewriteRule ^!static - [C]
RewriteRule ^(.*)$ static/$1 [PT]
+1

RewriteRule. :

RewriteEngine on
RewriteRule   ^/~(([a-z])[a-z0-9]+)(.*)  /home/$2/$1/.www$3

( http://httpd.apache.org/docs/2.0/misc/rewriteguide.html)

+1

Source: https://habr.com/ru/post/1752141/


All Articles