本文介绍了如何使用htaccess针对特定文件和文件夹将网站重定向到https和http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个wordpress网站,我只想将'/wp-admin'和'wp-login.php'的https更改为http.我想使用.htaccess来实现它,但是我不擅长正则表达式.以下是我当前的htaccess代码.
I have a wordpress site that I wanna change https to http for only '/wp-admin' and 'wp-login.php'. I wanna use .htaccess to achieve it, but I m not good at regular expressions. Below is my current htaccess codes.
# 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.如何修改呢?
Currently it works for wp-admin/, but not for /wp-login.php. How to modify this?
推荐答案
用以下内容替换您的规则:
Replace your Rules with this :
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]
在测试这些规则之前,请清除浏览器缓存.
Clear your browser cache before testing these rules.
这篇关于如何使用htaccess针对特定文件和文件夹将网站重定向到https和http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!