![](/img/trans.png)
[英]How can I redirect all pages to https, using .htaccess, with exceptions?
[英]How redirect all pages to 'https' using htaccess and Wordpress with a subdomain?
我需要将所有“ http”请求重定向到“ https”。 我做了这样的事情:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://example.com.br/site/$1 [R=301,L]
</IfModule>
看来工作正常,但这并未加载文件。 文件应使用url打开:
https://example.com.br/site/wp-content/themes/briefing/css/style.css
但是,该页面尝试加载:
https://example.com.br/site/css/style.css
“ https://”未出现在浏览器中。 我正在使用Wordpress,该站点位于“站点”文件夹中。 我的大问题是因为我有一个Ajax请求,并遇到以下错误:
XMLHttpRequest cannot load https://exemple.com.br/site/wp-content/themes/briefing/includes/loopHandler.php?numPosts=3&pageNumber=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com.br' is therefore not allowed access.
我的htacess文件开头为:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
我该怎么办?
您可以尝试:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.com/my-sub-domain/$1 [R,L]
</IfModule>
# END WordPress
您需要替换RewriteCond
:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
通过以下方式:
RewriteCond %{HTTPS} !on
您当前使用的HTTP:X-Forwarded-Proto
仅检查代理是否转发了非https流量。 这实际上与您的问题无关。 您需要常规检查传入请求是否不是https请求: %{HTTPS} !on
。
保持这样的规则:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com.br%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
https://
URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.