Apache 301重定向无法正常工作
我需要将运行在上的子域上的博客及其所有帖子重定向到新位置。当前位于Apache 301重定向无法正常工作,apache,.htaccess,redirect,mod-alias,ghost,Apache,.htaccess,Redirect,Mod Alias,Ghost,我需要将运行在上的子域上的博客及其所有帖子重定向到新位置。当前位于http://blog.example.com并需要重定向到http://example.com/blog/ 对于最初的Ghost博客,Apache被用作代理,因为Ghost在node.js上运行。因此,我不能简单地在Ghost安装的根文件夹中使用.htaccess 我使用a设置所有需要的重定向,然后将代码直接放入etc/apache2/sites enabled/000 default.conf,如下所示: <Virtua
http://blog.example.com
并需要重定向到http://example.com/blog/
对于最初的Ghost博客,Apache被用作代理,因为Ghost在node.js上运行。因此,我不能简单地在Ghost安装的根文件夹中使用.htaccess
我使用a设置所有需要的重定向,然后将代码直接放入etc/apache2/sites enabled/000 default.conf
,如下所示:
<VirtualHost *:80>
ServerName blog.example.com
Redirect 301 / http://example.com/blog/
Redirect 301 /post-title-1/ http://example.com/blog/post-title-1.html
Redirect 301 /post-title-2/ http://example.com/blog/post-title-2.html
Redirect 301 /post-title-3/ http://example.com/blog/post-title-3.html
</VirtualHost>
ServerName blog.example.com
重定向301/http://example.com/blog/
重定向301/post-title-1/http://example.com/blog/post-title-1.html
重定向301/后标题-2/http://example.com/blog/post-title-2.html
重定向301/后标题-3/http://example.com/blog/post-title-3.html
然后我重新启动了服务器
http://blog.example.com
现在已正确重定向到http://example.com/blog/
,但个别帖子指向错误的位置。它们不是应用新位置,例如post-title-1.html
,而是指向http://example.com/blog/post-title-1/
,逻辑上会引发404错误
感谢您的建议,如何解决此问题。您的规则顺序错误,即最通用的“一网打尽”规则是您的第一条规则,优先于其他规则 使用:
ServerName blog.example.com
重定向301/post-title-1/http://example.com/blog/post-title-1.html
重定向301/后标题-2/http://example.com/blog/post-title-2.html
重定向301/后标题-3/http://example.com/blog/post-title-3.html
重定向301/http://example.com/blog/
在测试之前,请确保清除浏览器缓存。没错,我不知道这些规则是按特定顺序应用的。现在它按预期工作。
<VirtualHost *:80>
ServerName blog.example.com
Redirect 301 /post-title-1/ http://example.com/blog/post-title-1.html
Redirect 301 /post-title-2/ http://example.com/blog/post-title-2.html
Redirect 301 /post-title-3/ http://example.com/blog/post-title-3.html
Redirect 301 / http://example.com/blog/
</VirtualHost>