繁体   English   中英

.htaccess-301重定向将所有页面移至https://-除1页外?

[英].htaccess - 301 redirect move all pages to https:// - except 1 page?

我有以下代码将任何http://请求重定向到https://-很好用,但是我将如何编辑它以使一页异常,例如mydomain.com/sitemap-news.xml-并保持此状态作为http://吗?

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

如评论中所列,这是我的.htaccess文件的外观

# BEGIN WordPress
  <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule !^sitemap-news\.xml$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} off
RewriteRule !^sitemap-news\.xml$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NE]

您可以为站点地图文件设置例外:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule !^sitemap-news\.xml$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} off
RewriteRule !^sitemap-news\.xml$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE,NE]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM