.htaccess 重定向到子目录中的脚本
我需要有一个 .htaccess 重写规则重定向到子目录根目录中的脚本,但仅限于该子目录中的任何文件/目录...
/
/subdir/
/index.php
/somedir/
/anotherdir/
对于上面的结构,我希望浏览到 /subdir 的任何人都转到 / subdir/index.php,以及任何去 /subdir/somedir/ 到 /subdir/index.php 等的人...
但是,如果他们去根目录。 他们应该留在那里......我已经尝试将 .htaccess 文件放入 /subdir 中,并尝试了一系列重写规则,但到目前为止没有任何效果。
更新:我并不是说只有/somedir/需要重定向到index.php,而是/subdir/的任何子目录都需要重定向被重定向...脚本也是如此,但显然不是 /subdir/index.php
抱歉,我之前不清楚。
I need to have a .htaccess rewrite rule redirect to a script in the root of a subdirectory, but only for any files/directories in that sub directory...
/
/subdir/
/index.php
/somedir/
/anotherdir/
For the structure above, I want anyone browsing to /subdir to go to /subdir/index.php, and anyone going to /subdir/somedir/ to /subdir/index.php etc...
If however, they go to the root directory. they should stay there... I've tried putting an .htaccess file in /subdir with a bunch of attempts at rewrite rules but so far none work.
update: I don't mean just the /somedir/ needs to redirect ot index.php, but any subdirectory of /subdir/ needs to be redirect... Scripts too, but obviously not /subdir/index.php
Sorry I wasn't clear before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解你的问题,唯一需要发生的实际重定向是如果有人转到 /subdir/somedir (将它们重定向回 index.php
如果是这种情况,这应该可以工作,放入 /.htaccess:
If I'm understanding your question, the only actual redirection that needs to happen is if someone goes to /subdir/somedir (redirect them back to the index.php
If that's the case, this should work, put in /.htaccess:
如果您只想要内部重定向,请尝试这个 mod_rewrite 示例
:外部重定向,只需添加
R
标志(带有可选的重定向状态代码:R=
xxx
;默认:302):If you just want an internal redirect, try this mod_rewrite example:
For an external redirect, just add the
R
flag (with an optional redirect status code:R=
xxx
; default: 302):