.htaccess redirects if file exists in subfolder

I have the following task. Assuming the following file is requested from the server: /pages/subfolder/mypage.php

Is there an option using mod-rewrite to do the following:

Look at a specific folder f. e. / USERMOD if the requested file (and structure) exists

If yes, execute this file with all parameters

If not, execute the requested file.

The background will be that the rewrite looks if / USERMOD has a replacement that has the same folder structure. If there is a replacement, use this file, otherwise we will use the original file.

Actually (but not working) I have:

RewriteCond %{REQUEST_URI} !^/USERMOD/ [NC]
RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]

Thanks for the help and help!

EDIT: full .htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/USERMOD/ [NC]
RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]

RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC]
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/admin/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/images/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_URI} (.*)?/templates/(.*)
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [L]

RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.+) - [L]

##boosted CONTENT
RewriteRule (.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?gm_boosted_content=$2&%{QUERY_STRING} [PT,L]

##boosted PRODUCTS
RewriteRule (.*/)?([A-Za-z0-9_-]+)\.html product_info.php?gm_boosted_product=$2&%{QUERY_STRING} [PT,L]

##boosted CATEGORIES
RewriteRule (.*/)?([A-Za-z0-9_-]+)/?.* index.php?gm_boosted_category=$2&%{QUERY_STRING} [L]
+4
1

:

RewriteEngine On

RewriteRule ^USERMOD/ - [NC,L]

RewriteCond %{DOCUMENT_ROOT}/USERMOD/$1 -f [NC]
RewriteRule ^(.*)$ /USERMOD/$1 [L]

# rest of your rules come here
+3

All Articles