简体   繁体   English

无法将页面和帖子URL的重定向从http重定向到Wordpress .htaccess文件中的https

[英]Redirect not working for Pages and Posts URLs from http to https in Wordpress .htaccess file

I am trying to redirect from http to https for my website. 我正在尝试从http重定向到我的网站的https。 The code I use is working for home page only and redirecting properly. 我使用的代码仅适用于主页,并且可以正确重定向。 for example it redirects correctly from http to https 例如,它可以正确地从http重定向到https

However the pages I create in my wordpress site can be accessed for both http and https for example a page can be accessed at both URLs below 但是,可以在http和https上访问我在wordpress网站中创建的页面,例如,可以在以下两个URL上访问该页面

http://www.example.com/any-page-url and https://www.example/any-page-url http://www.example.com/any-page-urlhttps://www.example/any-page-url

However I want all http pages redirect to respective https pages. 但是我希望所有的http页面都重定向到各自的https页面。 the htaccess file I use is 我使用的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 %{HTTPS} off    
   RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Have you try with putting your code top of htacces file. 您是否尝试将代码放在htacces文件的顶部。

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*)https:// % {HTTP_HOST}%{REQUEST_URI}

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

# END WordPress

If this is not works then try following code in place of your https redirect code 如果这不起作用,请尝试使用以下代码代替您的https重定向代码

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

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

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