在域名时将用户重定向到安全连接

时间:2018-01-18 10:16:28

标签: php apache .htaccess redirect mod-rewrite

我已经写了一条规则.htaccess它根据要求工作得很好现在需求略有变化我很困惑我怎么能通过改变我之前的规则来实现这个目标当用户点击域example.com或www.example.com时,用户应重定向到

  

https://www.example.com/blog/

此规则现在正在运行,下一个要求是当用户点击域

  

http://www.hkdcrandom.com/blog/lorem-ipsum/

OR

  

http://www.hkdcrandom.com/blog/lorem-ipsum/

他应该重定向到

  

https://www.hkdcrandom.com/blog/lorem-ipsum/

但是这件事不起作用是我到目前为止所写的规则。

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

# END WordPress

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

任何人都可以告诉我我做错了什么

1 个答案:

答案 0 :(得分:0)

我们目前使用

<IfModule mod_rewrite.c>
    # Force https and www
    RewriteCond %{SERVER_PORT} !=443
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

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

    # The rest of your rules
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
 </IfModule>