我有一个php文件的子文件夹。包含子文件夹.htaccess
像这样:domain.com/subfolder/file.php
这将是调用PHP文件,就好像他们是在根文件夹中,而不会忽略现有的根文件非常有用的。
有没有办法通过.htaccess包含子文件夹及其所有内容?
我有一个php文件的子文件夹。包含子文件夹.htaccess
像这样:domain.com/subfolder/file.php
这将是调用PHP文件,就好像他们是在根文件夹中,而不会忽略现有的根文件非常有用的。
有没有办法通过.htaccess包含子文件夹及其所有内容?
您可以使用以下规则根/的.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]
上面的RewriteConditions对于避免重写根文件夹和文件到/子文件夹很重要。
或者试试这个:
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]
这样的事情呢?
RewriteRule ^subfolder/(.*)$ $1
应该帮我觉得
PS请确保阿帕奇重写模块启用并在.htaccess文件打开的
第二个选项的作品!如何添加更多的文件夹?复制和粘贴相同的重写会做或它可以瓶颈服务器? –