如何解决将所有请求发送到php中的Inside文件夹?
文件夹结构:
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 文档).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。