2017-04-17 70 views
1

我有一個wordpress網站,我只想將https修改爲僅用於'/ wp-admin'和'wp-login.php'。我想使用.htaccess來實現它,但我不擅長正則表達式。以下是我目前的htaccess代碼。如何使用htaccess爲特定文件和文件夾將網站重定向到https和http

# Force HTTPS for /my 
RewriteCond %{HTTPS} !=on 
RewriteCond %{THE_REQUEST} !^[A-Z]+\s/wp-admin [NC] 
RewriteRule !^wp-admin https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L] 

# Force HTTP for anything which isn't /my 
RewriteCond %{HTTPS} =on 
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/wp-admin [NC] 
RewriteRule ^(wp-admin) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L] 

目前它適用於wp-admin /,但不適用於/wp-login.php。如何修改這個?測試這些規則之前

RewriteEngine on 
#http to https except "/wp-admit" and "/wp-login.php" 
RewriteCond %{HTTPS} !on 
RewriteRule ^((?!wp-admin.*|wp-login\.php).*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] 
#Redirect "/wp-admin" and "/wp-login.php" to http if accessed using https scheme 
RewriteCond %{HTTPS} on 
RewriteRule ^(wp-admin.*|wp-login\.php)$ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] 

清除瀏覽器緩存:

+1

你爲什麼要服務你的管理面板和通過HTTP登錄?當然**這些**是你希望HTTPS最安全的東西,對吧? – Bytewave

+0

正確的是,但在https中,我的100多個cforms不起作用。該網站以前在http。但是在安裝SSL之後,cforms出問題了。臨時解決方案是禁止在管理員儀表板上使用https – OneNation

回答

相關問題