如何使用特定文件和文件夹

时间:2017-04-17 01:56:22

标签: php wordpress .htaccess mod-rewrite

我有一个wordpress网站,我想将https更改为http仅用于'/ wp-admin'和'wp-login.php'。我想用.htaccess来实现它,但我不擅长正则表达式。以下是我目前的htaccess代码。

# 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。如何修改?

1 个答案:

答案 0 :(得分:1)

将此规则替换为:

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]

在测试这些规则之前清除浏览器缓存。