简体   繁体   English

htaccess强制重定向http,但wp-admin,wp-login.php和特定的URL除外

[英]htaccess force redirect http except wp-admin, wp-login.php and specific url

I have been struggling with .htaccess redirects with no luck. 我一直在努力.htaccess重定向,但没有运气。

I want all my site pages to be force redirected to http except wp-admin, wp-login.php and one below url. 我希望将所有站点页面都强制重定向到http,但wp-admin,wp-login.php和以下URL除外。

https://www.mysite.ie/grupai/grupai-foirm/ https://www.mysite.ie/grupai/grupai-foirm/

Could you please help. 能否请你帮忙。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

从wordpress数据库表wp-options网站网址和主网址更改

(e.g) http://localhost/wordpress

If you fail with htaccess, you can try to do that via WP itself. 如果htaccess失败,则可以尝试通过WP本身执行此操作。 By default all website works with HTTP. 默认情况下,所有网站均使用HTTP。 And this code detects current protocol and current page, if they need to be redirected, so it redirects them to https. 并且此代码检测当前协议和当前页面(如果需要重定向它们),因此它将它们重定向到https。

add_action('init','redirector',0);
add_action('admin_init','redirector',0);
function redirector(){
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
if ($protocol=='http://' and
(strpos($_SERVER["REQUEST_URI"],'wp-login')===false or
strpos($_SERVER["REQUEST_URI"],'wp-admin')===false or
strpos($_SERVER["REQUEST_URI"],'grupai/grupai-foirm')===false)){
header("location: https://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);
die();
}
}
# if not https
RewriteCond %{HTTPS} off

# and not wp-admin, etc
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{REQUEST_URI} !^/wp-login.php [NC]

# redirect to https 
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM