htaccess - IP 规范化到 HTTPS

htaccess - IP canonicalization to HTTPS

Google 云上的 Bitnami wordpress。

好的,下面的代码将所有内容都转移到 https 非 www,效果很好,但问题是我们无法获得专用 IP 重定向到 https url。请看下面;

RewriteEngine on


<ifModule mod_rewrite.c>
RewriteBase /

# IP REDIRECT CONANIZATION
RewriteCond %{HTTP_HOST} ^00\.00\.93\.114$
RewriteRule ^(.*)$ https://example.co.uk/ [L,R=301]


### WORKING HTTP to HTTPS / NON-WWW - WORKS

#if not example.co.uk then redirect to example.co.uk
RewriteCond %{HTTP_HOST} !^example\.co.uk$ [NC]
RewriteRule .* http://example.co.uk%{REQUEST_URI} [L,R=301]

#if not https
RewriteCond %{HTTPS} off
#redirect to https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

这里是 Bitnami 工程师。

从您在此处共享的配置文件来看,在我看来您正在尝试将所有传入请求重定向到 https://example.co.uk,这是真的吗?

为此,您可以编辑 /opt/bitnami/apache2/conf/bitnami/bitnami.conf 文件并设置以下行

<VirtualHost _default_:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.co.uk$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.co.uk [R=permanent,L]
...

<VirtualHost _default_:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.co.uk$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.co.uk [R=permanent,L]
...

这里有更多信息:

https://docs.bitnami.com/google/components/apache/#how-to-access-my-application-from-only-one-domain