B
B
bondle2020-10-14 13:08:05
Apache HTTP Server
bondle, 2020-10-14 13:08:05

Redirecting all requests to a folder except certain ones?

Structure roughly:

/public
   file.html
   index.html
/scr
  scr.php
/somedir
index.html

You need to redirect all requests to / public, except for those made to scr, that is
# В url
example.com/file.html
# На сервере подгружается 
/public/file.html
# В url
example.com
# На сервере подгружается 
/public/index.html

But when referring to scr
# В url
example.com/scr/scr.php
# На сервере подгружается 
/scr/scr.php


At the same time, it is necessary that the public url not be displayed when redirecting

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bondle, 2020-10-14
@bondle

I, who will face the same question in the future, catch

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/scr
RewriteCond %{DOCUMENT_ROOT}/public/$1/ !-d [NC]
RewriteRule ^((?!public/).*?)/?$ public/$1 [L,NC]

RewriteCond %{REQUEST_URI} !^/scr
RewriteCond %{DOCUMENT_ROOT}/public/$1 -d [NC]
RewriteRule ^((?!public/).+?)/?$ public/$1/ [L,NC]

And if you think that this solution is not correct, please tell me in the comments or answers the correct one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question