我已经发现了这个脚本改变的DocumentRoot:
I already found this script to "change the documentroot":
RewriteEngine on RewriteCond %{HTTP_HOST} ^your-domain-name$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.your-domain-name$ RewriteCond %{REQUEST_URI} !new-folder/ RewriteRule (.*) /new-folder/$1 [L]
这是简单和冷静,但我想补充脚本。我想重定向到文件/new-folder/index.php如果所需的文件不存在的里面的目录/新文件夹/ ,这样不仅%{REQUEST_URI }!-f ! 但我不知道如何获得当前脚本路径,如 __ __ DIR (PHP)在.htaccess中。 所以我的问题是,如何检查文件是否子目录(新文件夹)里面是否存在? 我的重定向将理论上是这样的:
It's simple and cool, but I want to complement the script. I want to redirect to the file /new-folder/index.php if the requested file does not exist inside the directory /new-folder/, so not only %{REQUEST_URI} !-f! But I don't know how to get the current script-path, like __DIR__ (PHP) in .htaccess. So my question is, how to check if a file exists inside a subdirectory (new-folder)? My redirect will theoretically look like:
RewriteEngine on RewriteCond %{HTTP_HOST} ^your-domain-name$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.your-domain-name$ RewriteCond %{REQUEST_URI} !./new-folder/ RewriteCond (PATH+Filename, if no filename is set, take index.php) !-f RewriteRule (.*) ./new-folder/index.php [L]
以上code使用./来检查相对的,它不知道,如果它的根里面!
The above code uses ./ to check relative, it does not know if it's inside the root!
此外,我想操纵REQUEST_URI:更换/新文件夹/从中,因此该文件夹中的脚本没有做到这一点。
Also I would like to manipulate the REQUEST_URI: replace the /new-folder/ from it, so scripts inside this folder don't have to do it
推荐答案您可以使用它像这样在你的根目录的.htaccess:
You can use it like this in your root .htaccess:
RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?your-domain-name\$ [NC] RewriteCond %{REQUEST_URI} !/new-folder/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/new-folder/$1 !-f [NC] RewriteCond %{DOCUMENT_ROOT}/new-folder/$1 !-d [NC] RewriteRule (.*) /new-folder/index.php [L]
另一种选择是使用在任何子目录 /anydirectory/.htaccess :
RewriteEngine On RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$ RewriteRule ^(.*)$ - [E=BASE:%1] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/%{ENV:BASE}new-folder/$1 !-f [NC] RewriteCond %{DOCUMENT_ROOT}/%{ENV:BASE}new-folder/$1 !-d [NC] RewriteRule (.*) %{ENV:BASE}new-folder/index.php [L]更多推荐
重定向到内部Web目录
发布评论