.htaccess - 301 重定向根目录而不将新根目录级联到所有其他 301 重定向
问题描述
我已成功将站点的根目录重定向到另一个站点的子目录:
#Redirect Root to subdirectory on example.com
RewriteEngine On
RewriteRule ^$ http://example.com/subdirectory [L]
我的所有其他重定向都遇到了麻烦。新根目录 (/subdirectory) 的子目录被插入到每个路径之前的重定向中,这导致重定向中断。
例子:
Redirect 301 /contact-us/ https://www.example.com/company/contact.shtml
试图指向
https://www.example.com/subdirectorycompany/contact.shtml
简而言之,我可以让 root 工作,或者我可以让重定向工作——但不能同时工作。任何人都可以提供一些见解吗?
我已经阅读了很多帖子,这就是我所取得的成就,但我可以使用一些帮助,谢谢。
解决方案
不要混合Redirect
指令,RewriteRule
因为它们来自不同的 Apache 模块并且在不同的时间被调用。
最好有这样的所有规则:
RewriteEngine On
# all specific 301 redirects go here
RewriteRule ^contact-us/?$ https://example.com/company/contact.shtml [L,NC,R=301]
#Redirect Root to subdirectory on example.com
RewriteRule ^$ http://example.com/subdirectory [L,R=301]
推荐阅读
- angular - Angular 7 - 如何从表单中获取已编辑的字段
- react-native - 为 Facebook 应用审查创建一个模拟器构建。(不存在捆绑 URL)
- c# - 如何使用 C# 从包含大量其他文件或文件夹的文件夹中正确删除 .Net Core 中的文件
- python - 导入模块时是否可以创建符号链接或快捷方式?
- android - 使用导航、片段工厂和 Dagger 2 时尝试将 navGraph 与 NavHostFragment 关联时出现 Stackoverflow 错误?
- jquery - jQuery - 具有不同元素的相同函数()
- angular - '未捕获的 HttpErrorResponse' Jasmine 测试失败
- python - 使用 exec 和返回结果从 golang 内联 python3
- excel - 将单元格向左移动而不影响其自己的列
- raspberry-pi - 从 Raspberry pi 的源代码构建 Linphone