我有一个包含有效 htaccess 文件的域,它将所有 http 流量重定向到 https。这一切都很好。
这是 .htaccess 文件:
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]
刚才,我已经在名为“blogg”的子文件夹中安装了 wordpress,如下所示:
www.example.com/blogg/
我立即注意到该博客不是 https。所以我去了 wordpress 管理员,将常规设置中的 URL 从“http”更改为“https”。这似乎使 wordpress 中的所有链接以及管理页面都使用 https。
不幸的是,在网络浏览器中访问 blogg 时它没有帮助,它仍然是 http,尽管如果我在浏览器中手动输入 https 可以工作。
这是 wordpress 目录 (example.com/blogg/.htaccess) 中的 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
我是 .htaccess 的新手,希望得到一些帮助来为我的所有域(包括博客)找到正确的 https 域代码。感谢帮助。 明确地说,我希望所有的 http 请求都自动转到 https。
我已经尝试在第二个 .htaccess 文件中添加这一行:(虽然运气不好)。
RewriteCond %{HTTPS} off RewriteRule ^(.*)$
https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
BR
最佳答案
你可以试试这样的:
# 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
您也可以查看此代码,因为它是一个更简单的版本。如果也在根文件夹中,它会让您了解 WP htaccess。 :)
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
关于php - 子文件夹中的 wordpress htaccess 未重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55089551/