使用.htaccess文件将http://example.org/sitemap.xml转发到https://example.org/sitemap.xml

时间:2014-10-15 23:26:17

标签: xml wordpress apache .htaccess

我问的问题在标题中很多。

如何使用.htaccess文件将http://example.org/sitemap.xml转发到https://example.org/sitemap.xml

我需要这样做,因为我使用的wordpress插件不会索引ssl加密的页面,而如果站点地图本身也是https,则包含页面,那么如何使用.htaccess重定向人员,我在.htaccess中有这个但是它似乎不起作用

# BEGIN Custom Edits

#//301 Redirect Old File
Redirect 301 http://example.org/sitemap.xml https://example.org/sitemap.xml

# END Custom Edits

2 个答案:

答案 0 :(得分:2)

使用以下规则集:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(sitemap\.xml)$ https://%{HTTP_HOST}/$1 [R,L]

答案 1 :(得分:1)

您的重定向行的问题是第一个网址应该是路径,而不是完整的网址。你想要的更像是:

Redirect permanent /sitemap.xml https://example.org/sitemap.xml