Htaccess mod-rewrite: link to subdirectory from root-neglect dirs in subdirectory?

I asked part of this question some time ago in stackoverflow, and it works fine: es

I have a multi-domain server, each directory corresponds to a domain name. However, my primary domain name www.mydomain.com is also a directory on my server and is not automatically linked.

That is why I use this in my root website ...

root /.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/my-website/
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -d
RewriteRule ^(.*)$ /my-website/$1 [L]

Now, when I call www.my-website.com, it automatically starts the directory /my-website. This is just great. However, in this directory I have another .htaccess file with this in it.

root / my site / .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^/projects/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^/jobs/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^(/downloads/.+)/?$ assets/$1 [L,NC]

, , , /projects/, "" .

, - - main-htaccess , RewriteConditions , " "

?

+1
2

:

DocumentRoot/.htaccess:

RewriteEngine On
RewriteBase /

RewriteRule ^projects/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^jobs/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^(downloads/.+)/?$ assets/$1 [L,NC]

# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_URI} !^/my-website/
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -d
RewriteRule ^(.*)$ /my-website/$1 [L]

/my-website/.htaccess:

RewriteEngine On
RewriteBase /my-website/

# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/my-website/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
0

, . , , , :

mod_rewrite .htaccess , , . , .htaccess ,

RewriteOptions Inherit

. . , . , .htaccess.

3 RewriteRule "/" , , . , .htaccess( ), , / . . RewriteRule.

0

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


All Articles