将apache重定向从http重定向到https以获取特定URL

时间:2012-03-21 04:21:51

标签: redirect apache httpd.conf mod-alias

我想将具有/ test的任何网址路径重定向到https://localhost/test。此外,如果网址为/ test?user = 123,则必须将其重定向到https://localhost/test?user=123,或者更确切地说,如果网址为/ test / test_db / user,则必须将id = 123& pwd = 123重定向到{{ 3}}

任何类型的所有其他请求都必须重定向到根文件夹中的“拒绝访问”的html页面(http://localhost/accessdenied.html)。

如何使用apache中的RedirectMatch实现此目的。我试过像

这样的东西
RedirectMatch permanent ^test/(.*)$ https://localhost/test/$1

哪个不起作用。

2 个答案:

答案 0 :(得分:1)

我想知道这是否更好作为ServerFault问题。

反正:
我不知道如何使用RedirectMatch实现这一目标,但我知道如何使用ModRewrite实现这一目标:

RewriteEngine On$
RewriteCond %{HTTPS} off$
RewriteRule ^/bla https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]$

这是一个非常通用的形式,可以用于任何HTTP主机(因为我不知道有关您的主机的任何详细信息),并将重定向与URL开头的bla匹配的任何内容已经Https,有论据和一切。

答案 1 :(得分:0)

在我的Apache httpd 2.2服务器上,这对我来说很好用:

RedirectMatch 301 ^(/someprefix[^/]*/.*)$ https://hostname$1
相关问题