通过.htaccess从HTTPS重定向到IP地址到域名

问题描述 投票:0回答:1

我正在尝试通知IP以重定向到域名,但由于某些原因,它将无法正常工作并且不断使用https://www.111.111.111.11

这是我在.htaccess中使用的内容

 RewriteEngine On
 RewriteBase /

 #Uncomment lines below when uploading to the live server
 RewriteCond %{HTTP_HOST} ^111\.111\.111\.11$ [NC,OR]
 RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.org$ [NC]
 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteCond %{SERVER_PORT} 80
 RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
 RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
 RewriteCond %{HTTPS} off
 RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
 RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
 RewriteCond %{HTTP_HOST} !^(www\.)example\.org$ [NC]
 RewriteRule ^.*$ https://www.example.org[L,R=301]
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^https://(www\.)?example\.org/.*$ [NC]
 RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F]

此外,plesk负责从example.orgwww.example.org以及从httphttps的安全SEO重定向。

我对.htaccess规则不是很熟悉,但即使对我来说,我看起来有一些不必要的线条。

有人可以帮忙吗?

提前致谢

.htaccess mod-rewrite
1个回答
1
投票

在公共目录中,您必须确保000-default.conf文件已设置AllowOverride All,因此将使用.htaccess文件中的设置。

在.htaccess文件中使用以下命令:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^111\.22\.33\.44$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.