Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重定向到子目录中的脚本_.htaccess_Redirect_Subdirectory - Fatal编程技术网

.htaccess重定向到子目录中的脚本

.htaccess重定向到子目录中的脚本,.htaccess,redirect,subdirectory,.htaccess,Redirect,Subdirectory,我需要将.htaccess重写规则重定向到子目录根目录中的脚本,但仅适用于该子目录中的任何文件/目录 / /subdir/ /index.php /somedir/ /anotherdir/ 对于上面的结构,我希望任何浏览/subdir的人都可以转到/subdir/index.php,任何浏览/subdir/somedir/to/subdir/index.php的人都可以 但是,如果是,它们将转到根目录。他们应该呆在那里。。。我尝试过在/subdir中放入一个.htacces

我需要将.htaccess重写规则重定向到子目录根目录中的脚本,但仅适用于该子目录中的任何文件/目录

/
/subdir/
   /index.php
   /somedir/
   /anotherdir/
对于上面的结构,我希望任何浏览/subdir的人都可以转到/subdir/index.php,任何浏览/subdir/somedir/to/subdir/index.php的人都可以

但是,如果是,它们将转到根目录。他们应该呆在那里。。。我尝试过在/subdir中放入一个.htaccess文件,并多次尝试重写规则,但到目前为止都没有成功

更新:我不是说只/somedir/需要重定向ot index.php,而是/subdir/的任何子目录都需要重定向。。。脚本,但显然不是/subdir/index.php


抱歉,我之前不清楚。

如果我理解您的问题,唯一需要进行的实际重定向是如果有人转到/subdir/somedir,将他们重定向回index.php

如果是这样的话,这应该是可行的,请输入/.htaccess:

redirect /subdir/somedir/ /subdir/

如果只需要内部重定向,请尝试以下示例:

对于外部重定向,只需添加带有可选重定向状态代码的R标志:R=xxx;默认值:302:

RewriteRule … [L,R=xxx]
RewriteRule … [L,R=xxx]