如何使用htaccess将博客重定向到另一个网址

How to redirect blog to another url using htaccess

提问人:Khan 提问时间:9/23/2023 最后编辑:Khan 更新时间:9/28/2023 访问量:27

问:

我最近将我的博客移到了谷歌正在寻找不存在的沼泽页面的问题上,我想使用 htaccess 重定向各个博客,如下所示:https://mobileframers.com/bloghttps://blog.domain.com

Redirect https://mobileframers.com/blog https://blog.mobileframers.com

Redirect https://mobileframers.com/blog/test-1 https://blog.mobileframers.com/test-1

Redirect https://mobileframers.com/blog/test-2 https://blog.mobileframers.com/test-2

Linux Apache .htaccess

评论

2赞 CBroe 9/25/2023
对于初学者:该指令在完整 URL 上不匹配。httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect:“旧的 URL 路径是以斜杠开头的区分大小写(%解码)路径。不允许使用相对路径。Redirect

答:

0赞 volkerschulz 9/28/2023 #1

要将所有请求从具有子目录的旧域重定向到没有子目录的新域,同时保留路径的其余部分和完整的查询字符串,请在 .htaccess 中使用mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/blog/(.*)$
RewriteRule ^(.*) https://blog.mobileframers.com/%1 [R=301,NC]