如何将IP重定向到域名? [英] How to redirect ip to domain name?
本文介绍了如何将IP重定向到域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Apache Web服务器,我想将所有URL从ip重定向到域。这是我的网站 .htaccess
文件的内容:
I use Apache web-server and I want to redirect all urls from ip to domain. Here is the content of my website .htaccess
file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]
根据一些研究,我想我需要这样的东西:(不确定)
According to some research, I guess I need something like this: (not sure)
RewriteBase /
RewriteCond %{HTTP_HOST} ^95\.216\.161\.63$
RewriteRule ^([\s\S]*)$ https://lamtakam.com/$1 [L,R=301]
但是我不知道该如何(在哪一部分中)将这三行添加到 .htaccess
文件中。有任何线索吗?
But I don't know how (in which part) should I add those threelines to the .htaccess
file. Any clue?
推荐答案
您应该在 https / www $ c之前或之后插入IP重定向规则。 $ c>重定向规则:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^95\.216\.161\.63$
RewriteRule ^ https://lamtakam.com%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]
如果要使IP匹配条件更通用,则使用:
If you want to make your IP matching condition more generic then use:
RewriteCond %{HTTP_HOST} ^\d+\.\d+\.
能够匹配任何IP地址。
to be able to match any IP address.
这篇关于如何将IP重定向到域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文