在目标中将RedirectMatch与HTTP

编程入门 行业动态 更新时间:2024-10-28 17:27:47
本文介绍了在目标中将RedirectMatch与HTTP_HOST一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在阅读,如果可能的话,我不应该使用mod_rewrite.因此,我正在尝试使用RedirectMatch进行http到https的重写.

I keep reading that, where possible, I should not be using mod_rewrite. As such, I am trying to do a http to https rewrite with RedirectMatch.

问题:如何在URL参数中使用RedirectMatch并使用Apache服务器变量(例如%{HTTP_HOST})?

Question: How can I use RedirectMatch and use Apache server variables (such as %{HTTP_HOST}) in the URL parameter?

此代码无法将响应返回给客户端(Chrome):

This code fails to return a response to the client (Chrome):

RedirectMatch ^(.*) %{HTTP_HOST}/$1

我最近问了一个与此类似的问题,但它可能过于罗word,缺乏答案的方向:在Apache中将HTTP流量重定向到https,而无需使用mod_rewrite

I recently asked a similar question to this, but it may have been too wordy and lacks direction for an answer: Redirecting http traffic to https in Apache without using mod_rewrite

推荐答案

否,您不能在Redirect/RedirectMatch中使用该类型的变量.如果需要变量,例如%{HTTP_HOST},请使用mod_rewrite.

No, You can't use variables of that type with Redirect/RedirectMatch. If you need variables, such as %{HTTP_HOST}, use mod_rewrite.

注意:我建议您不要立即尝试使用mod_rewrite,因为即使是最简单的重定向,大多数人也会选择使用mod_rewrite,这显然是过分的,而且大多数情况下,它只是在不必要地使事情复杂化.

Note: I commend you for not trying to use mod_rewrite right away, because most people will go for mod_rewrite even for the simplest of redirections, which is clearly overkill and most times it is just looking to complicate things unnecessarily.

更多推荐

在目标中将RedirectMatch与HTTP

本文发布于:2023-11-14 13:15:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   目标   HTTP   RedirectMatch

发布评论

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

>www.elefans.com

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