我需要一个.htaccess重写规则重定向到子目录根目录中的脚本,但只对子目录中的任何文件/目录.
/
/subdir/
/index.php
/somedir/
/anotherdir/对于上面的结构,我希望任何浏览到/subdir的人转到/subdir/index.php,任何人到/subdir/somedir/ to /subdir/index.php等等.
但是,如果它们转到根目录。他们应该呆在那里..。我尝试过在/subdir中放置一个/subdir文件,尝试了多次重写规则,但到目前为止都没有效果。
更新:--我的意思不只是/ index.php /需要重定向,而是/subdir/的任何子目录都需要重定向.脚本也是,但显然不是/subdir/index.php
抱歉我之前没说清楚。
发布于 2009-02-06 21:51:27
如果我理解你的问题,唯一真正需要发生的重定向是某人转到/subdir/somedir (将他们重定向回index.php )
如果是这样的话,应该可以使用/.htaccess:
redirect /subdir/somedir/ /subdir/发布于 2009-02-06 22:01:42
如果您只想要内部重定向,请尝试以下重写示例:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/subdir/somedir/index\.php
RewriteRule ^subdir/somedir/ subdir/index.php [L]对于外部重定向,只需添加R标志(带有可选的重定向状态代码:R=xxx;默认值: 302):
RewriteRule … [L,R=xxx]https://stackoverflow.com/questions/521019
复制相似问题