2014-01-24 32 views
1

我需要將所有「http」請求重定向到「https」。我做了這樣的事情:如何使用htaccess和WordPress的子域重定向所有頁面'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> 

我該怎麼辦?

回答

0

您需要更換RewriteCond

RewriteCond %{HTTP:X-Forwarded-Proto} !https 

通過如下:

RewriteCond %{HTTPS} !on  

HTTP:X-Forwarded-Proto您目前我們ing僅檢查代理是否轉發了非https流量。這不是真的與你的問題有關。如果傳入的請求不是https請求,您需要進行一般檢查:%{HTTPS} !on

+0

謝謝,但文件沒有正確加載,仍然嘗試加載「http」 –

+0

您是否啓用了mod_rewrite ? – hek2mgl

+0

是的,似乎它工作,但仍然存在與wordpress文件加載問題。文件應該使用url:https://example.com.br/site/wp-content/themes/briefing/css/style.css打開,但是頁面嘗試加載:https://example.com。 BR /網站/ CSS/style.css中 –

0

你可能可以嘗試:

# 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 
+0

嗨,似乎它的工作,但仍然存在與wordpress文件加載問題。應使用以下網址打開文件: https://example.com.br/site/wp-content/themes/briefing/css/style.css 但相反,頁面嘗試加載: https:/ /example.com.br/site/css/style.css –

+0

DB中的變量是否正確?嘗試喲確定wp_options表中的「site」和「home」記錄指向您的網站安裝的根網址 –

0

讓你的規則是這樣的:

<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> 
  • 那麼一定要確保你的家庭和網站的網址在WP的永久鏈接設置也有https://網址。
相關問題