使用 htaccess 从重定向中排除图像 URL



我的旧博客在 www.example.com/myblog我更改了服务器,我想使用 www.example.com/blog

为此,我使用了htaccess代码重定向 301/我的博客 http://www.example.com/blog

这有助于重定向博客主页和单个博客文章。

这些图像被放在新服务器中一个名为myblog的文件夹中。所以图片网址是 www.example.com/myblog/wp-content/uploads/2010/04/something.jpg

但是我上面写的 htaccess 将其重定向到 www.example.com/blog/wp-content/uploads/2010/04/something.jpg 返回 404。

任何人都可以帮助我编写 htaccess 代码来重定向仅排除博客图像 URL 的博客文章 URL?

不要使用 mod_alias 和 Redirect 指令,请尝试mod_rewrite并添加一些条件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?myblog/(.*)$ http://www.example.com/blog/$1 [L,R=301]
# redriect the index
RewriteRule ^/?myblog/?$ http://www.example.com/blog/ [L,R=301]

最新更新