I have a sub folder with php files.
Like this: domain.com/subfolder/file.php
It would be very useful to call the php files as if they were on the root folder, without ignoring the existing root files.
Is there a way to include a subfolder and all its contents through .htaccess?
You can use the following rule in root/.htaccess :
RewriteEngine on
#1--If the request is not for an existent root directory--#
RewriteCond %{REQUEST_FILENAME} !-d
#2--And the request is not for an existent root file--#
RewriteCond %{REQUEST_FILENAME} !-d
#3--Then, rewrite the request to "/subfolder"--#
RewriteRule ^([^/]+)/?$ /subfolder/$1 [NC,L]
The RewriteConditions above are important to avoid rewriting your root folder and files to /subfolder.
Or try this :
RewriteEngine on
#--if /document_root/subfolder/foo is an existent dir--#
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -d [OR]
#--OR /document_root/subfolder/foo is an existent file--#
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -f
#--rewrite "/foo" to "/subfolder/foo--#
RewriteRule ^(.+)$ /subfolder/$1 [NC,L]
How about something like this?
RewriteRule ^subfolder/(.*)$ $1
It should help I think
PS please make sure that apache rewrite module is enabled and turned of in .htaccess file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.