重定向到内部Web目录

编程入门 行业动态 更新时间:2024-10-18 20:28:32
本文介绍了重定向到内部Web目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经发现了这个脚本改变的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目录

本文发布于:2023-11-01 02:06:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   目录   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!