【发布时间】:2016-04-21 18:14:12
【问题描述】:
我正在尝试使用主目录的 .htaccess 文件中的 RewriteRule 将一个子目录重定向到另一个子目录。
例如:http://website.com/subdir 应重写为 http://website.com/another_dir/destination_dir,但用户仍应在地址栏中看到 http://website.com/subdir。
如果用户使用尾部斜杠结束 URL,这将非常有效。示例:http://website.com/subdir/(生成 200
但是,如果省略斜杠,则会生成 301 重定向,并且我们会看到不需要的目标目录。例如,http://website/subdir 将用户重定向到http://website/another_dir/destination_dir
以下是 .htaccess 的相关部分:
# URL Rewriting:
RewriteEngine On
RewriteBase /
...
# Redirect subdirectories:
RewriteRule ^subdir(.*)$ another_dir/destination_dir$1 [PT,NC,QSA,L]
感谢任何帮助!
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect