doomm4711 2019-03-10 15:59
浏览 75

子文件夹中的wordpress htaccess未重定向到https

I have a domain with a working htaccess file, which redirects all http traffic to https. This is/was working all fine.

Here is that .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Just now, I have installed wordpress in a sub-folder called "blogg" like this:

www.example.com/blogg/

I noticed right away that the blog was not https. So I went to wordpress admin and changed the URL in general settings from "http" to "https". This seems to have made all links in wordpress, as well as the admin page, use https.

Unfortunately it didnt help when going to the blogg in the web browser, it is still http, although https works if I enter it manually in the browser.

Here is the htaccess file in the wordpress directory (example.com/blogg/.htaccess):

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

I am new to .htaccess, and would like some help in finding the right code for all my domain to be https, including the blog. Help is appreciated. To be clear, I want all http requests to automatically go to https instead.

I have tried adding this line in the second .htaccess file: (no luck though).

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

BR

  • 写回答

1条回答 默认 最新

  • donglugou6652 2019-03-10 16:13
    关注

    You can try something like this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blogg/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blogg/index.php [L]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]    //SERVER_NAME = your actual domain name for WP
    </IfModule>
    # END WordPress
    

    You can also look into this code since its an easier version. It will give you idea about WP htaccess if in root folder as well. :)

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L,NE]
    
    # 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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)