在目标中将RedirectMatch与HTTP_HOST一起使用 [英] Using RedirectMatch with HTTP_HOST in the destination

查看:91
本文介绍了在目标中将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 ^(.*) https://%{HTTP_HOST}/$1

我最近问了一个与此类似的问题,但它可能过于罗word,缺乏答案的方向:

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_HOST一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆