【发布时间】:2019-11-02 21:03:36
【问题描述】:
我在“example.com/a”中有一个站点,并且想将 301 重定向,只是将 url “example.com/a”重定向到“example.com/b”,而“example.com/a”中的其他数据不换地址。
在“example.com/a”中创建 .htaccess 并尝试使用以下代码:
RewriteEngine on
RewriteRule ^$ http://www.example.com/b [R=301,L]
和
RedirectMatch 301 ^/$ https://example.com/b
及其重定向根目录,但“example.com/a”中的所有其他数据显示 404 错误。
我在“root/a”中有很多照片,只是想将“root/a”地址重定向到“root/b”,并且照片的地址保持不变。
例如“root/a/pic.jpg”地址在重定向前后保持不变,
我怎样才能只重定向“example.com/a”而其他旧地址不改变?
【问题讨论】:
-
您的任何一条规则都应该已经满足您的要求 - 尽管如果
/b是物理目录,您应该重定向到/b/(带有尾部斜杠)。 “但example.com/a中的所有其他数据都显示 404 错误” - 此 redirect 不会导致该错误 - 一定有 其他事情 正在发生。 (确保您的浏览器缓存已清除。)