Apache的httpd.conf重定向IP到主机名 [英] Apache httpd.conf for redirecting ip to hostname
问题描述
我有外部IP和主机名设置为我的机器。
I have external IP and hostname configured for my machine.
在应用程序中,我只使用域名访问的API。所以,当我尝试通过IP地址来访问我的API,它显示302移动暂时的错误。
因此,请求(主页),点击IP地址的服务器上,它应该重定向到主机名。
Inside the application, I am using only the domain names to access the APIs. So when i try to access my APIs through IP address, it shows 302 Moved temporarily error. So, for request(for Homepage) that hits the server with IP address, It should redirect to hostname.
即,当用户点击的https://XX.XX.XX.XX/main 该应重定向到 https://ayz-abc.mysite.com/main
That is, when user hits https://XX.XX.XX.XX/main it should be redirected to https://ayz-abc.mysite.com/main
有关这一点,我使用重定向Apache中的httpd.conf中尝试。
For this I tried using the redirect in httpd.conf of apache.
<VirtualHost XX.XX.XX.XX>
DocumentRoot "/var/www/html"
#ServerName ayz-abc.mysite.com/
# Other directives here
RewriteEngine On
RewriteRule /.* https://ayz-abc.mysite.com/ [R]
</VirtualHost>
我也曾尝试用下面的
I have also tried with the following
<VirtualHost *.portnum>
DocumentRoot "/var/www/html"
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule https://XX.XX.XX.XX/main https://ayz-abc.mysite.com/main [R=301,L]
</VirtualHost>
Plsssss帮助我。
Plsssss help me.
推荐答案
确定。你缺少一个重写条件
Ok. You are missing a rewrite condition
<VirtualHost XX.XX.XX.XX>
DocumentRoot "/var/www/html"
#ServerName ayz-abc.mysite.com/
# Other directives here
RewriteEngine On
RewriteCond %{HTTP_HOST} !^ayz-abc.mysite.com$
RewriteRule /.* https://ayz-abc.mysite.com/ [R]
</VirtualHost>
如果您不包括这种情况下它甚至会与主机重定向
If you don't include this condition it will redirect even with the hostname
这篇关于Apache的httpd.conf重定向IP到主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!