Php 如何停止子文件夹重定向到根目录

Php 如何停止子文件夹重定向到根目录,php,.htaccess,redirect,mod-alias,Php,.htaccess,Redirect,Mod Alias,我的网站托管在根文件夹中,根文件夹指向,我的子文件夹位于root/upload中,指向www.upload.com 现在当我使用 RewriteBase / Redirect 302 /index.html http://www.example.com/index.php 现在这两个example.com/index.html都被重定向到example.com/index.php 并且upload.com/index.html被重定向到example.com/index.php 如何避免up

我的网站托管在根文件夹中,根文件夹指向,我的子文件夹位于root/upload中,指向www.upload.com

现在当我使用

RewriteBase /

Redirect 302 /index.html http://www.example.com/index.php
现在这两个example.com/index.html都被重定向到example.com/index.php

并且upload.com/index.html被重定向到example.com/index.php


如何避免upload.com/index.html重定向到example.com/index.php

使用重定向指令无法避免此重定向,您需要使用mod rewrite with conditions

在htaccess中尝试以下代码:

RewriteEngine on
#IF http_host=="www.example.com"#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
#redirect "/index.html" to "/index.php"#
RewriteRule ^index\.html$ /index.php [NC,L,R,NE]

使用重定向指令无法避免此重定向,您需要使用带条件的mod rewrite

在htaccess中尝试以下代码:

RewriteEngine on
#IF http_host=="www.example.com"#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
#redirect "/index.html" to "/index.php"#
RewriteRule ^index\.html$ /index.php [NC,L,R,NE]