[英]apache redirect loop in virtual host
I have the entry below in my .conf file that I set up for Jenkins. 我在为Jenkins设置的.conf文件中有以下条目。
<VirtualHost *:80>
ServerName my.server.com
Redirect 301 / http://my.server.com/factory
ProxyPass /factory http://localhost:8080/factory nocanon
ProxyPassReverse /factory localhost:8080/factory
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/factory*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
I redirect fine from my.server.com as expected. 我按预期从my.server.com重定向正常。 But, if I put a URL that doesn't exist such as my.server.com/test it sends me into a redirect loop. 但是,如果我输入了一个不存在的URL(例如my.server.com/test),它将使我进入重定向循环。 I am ok with non existent URLs like /test showing 404 pages, I just want my home page to redirect to /factory. 我可以使用不存在的URL(例如显示404页的/ test),可以,我只希望我的主页重定向到/ factory。
My Apache knowledge is currently about 0, so if you can explain like I'm 5 that would be great. 我的Apache知识目前大约为0,因此,如果您能像我5岁那样进行解释,那就太好了。 I'm just trying to get this up and running and plan on continually learning as I go. 我只是想让它开始运行并计划在我继续学习的过程中继续学习。
First load mod_rewrite in your Apache and try updated config below. 首先在您的Apache中加载mod_rewrite,然后尝试以下更新的配置。
<VirtualHost *:80>
ServerName my.server.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my\.server\.com$ [NC] # if host is my.server.com
RewriteCond %{REQUEST_URI} !(^/factory$) [NC] # and request uri is NOT factory
RewriteRule ^(.*)$ http://my.server.com/factory [R=301,L] # redirect to url
ProxyPass /factory http://localhost:8080/factory nocanon
ProxyPassReverse /factory localhost:8080/factory
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/factory*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.