将所有请求发送到 php 中的内部文件夹?

Send all Request to Inside folder in php?

sharedHostingFolder

folder1

folder2

folder3

xampp htdocs folder

文件夹结构:

root/sharedHostingFolder
-need an .htaccess file here
-folder1
        --index.php
        --dude.php
-folder2
        --hello.php
        --index.php
        ---folder5
                       ----index.php
-folder3
        --hi.php
        --index.php

请求结构

Request "root/sharedHostingFolder/hello.php"         will show file inside   "root/sharedHostingFolder/folder2/hello.php"

Request "root/sharedHostingFolder/"                  will show file inside   "root/sharedHostingFolder/folder2/index.php"

Request "root/sharedHostingFolder/folder1/dude.php"  will show file inside   "root/sharedHostingFolder/folder1/dude.php"

Request "root/sharedHostingFolder/folder1/"          will show file inside   "root/sharedHostingFolder/folder1/index.php"

Request "root/sharedHostingFolder/folder2/hello.php" will show file inside   "root/sharedHostingFolder/folder2/hello.php"

Request "root/sharedHostingFolder/folder2/"          will show file inside   "root/sharedHostingFolder/folder2/index.php"

Request "root/sharedHostingFolder/folder3/hi.php"    will show file inside   "root/sharedHostingFolder/folder3/hi.php"

Request "root/sharedHostingFolder/folder5/"          will show file inside   "root/sharedHostingFolder/folder2/folder5/index.php"


我无法访问 php.ini 文件

.htaccess 文件

RewriteEngine on
DirectoryIndex index.php
RewriteCond %{REQUEST_URI} ^/folder1/ [OR]
RewriteCond %{REQUEST_URI} ^/folder2/ [OR]
RewriteCond %{REQUEST_URI} ^/folder3/
RewriteRule - [END]
RewriteRule ^ /folder2%{REQUEST_URI} [END]

httpd.conf 文件:

<Directory />
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>



错误:

object not found

我研究并发现 .htaccess 可以轻松做到这一点。但是,我真的不知道该怎么做。

这是一个奇怪的问题。对我来说,它读起来有点像经典的 xy 问题......就好像你没有问如何解决你的实际任务,而是如何让你认为 可能 解决你的问题任务...

无论如何,看着你的例子,我的印象是几乎没有什么可以做的,主要是一些需要作为重写规则实现的例外。所以像这样:

RewriteEngine on
DirectoryIndex index.php

RewriteCond %{REQUEST_URI} ^/sharedHostingFolder/folder1/ [OR]
RewriteCond %{REQUEST_URI} ^/sharedHostingFolder/folder2/ [OR]
RewriteCond %{REQUEST_URI} ^/sharedHostingFolder/folder3/
RewriteRule - [END]

RewriteRule ^ /sharedHostingFolder/folder2%{REQUEST_URI} [END]

这使得对以其中一个文件夹名称开头的 URI 的请求保持不变,回复经典文件系统映射并将 index.php 脚本定义为这些文件夹的回退逻辑。并将其他所有内容映射到 folder2.

从您的问题中并不清楚“www”字符串的含义。如果这意味着表示另一个文件夹级别,那么您可能必须将该级别添加到上面的规则中。

显然,需要启用重写模块才能使其正常工作。最好是在 http 服务器的主机配置中实施此类规则。如果您无权访问它,您也可以使用分布式配置文件(“.htaccess”),但您需要为请求的位置启用此类文件的解释(请参阅有关 AllowOverride 指令的 apache 文档).