Apache的httpd.conf重定向IP到主机名

编程入门 行业动态 更新时间:2024-10-27 14:30:35
本文介绍了Apache的httpd.conf重定向IP到主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有外部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 该应重定向到 ayz-abc.mysite/main

That is, when user hits XX.XX.XX.XX/main it should be redirected to ayz-abc.mysite/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/ # Other directives here RewriteEngine On RewriteRule /.* ayz-abc.mysite/ [R] </VirtualHost>

我也曾尝试用下面的

I have also tried with the following

<VirtualHost *.portnum> DocumentRoot "/var/www/html" RewriteEngine On RewriteCond %{HTTPS} on RewriteRule XX.XX.XX.XX/main ayz-abc.mysite/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/ # Other directives here RewriteEngine On RewriteCond %{HTTP_HOST} !^ayz-abc.mysite$ RewriteRule /.* ayz-abc.mysite/ [R] </VirtualHost>

如果您不包括这种情况下它甚至会与主机重定向

If you don't include this condition it will redirect even with the hostname

更多推荐

Apache的httpd.conf重定向IP到主机名

本文发布于:2023-07-16 04:04:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   主机名   httpd   Apache   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!