3

我想将任何具有 /test 的 URL 路径重定向到https://localhost/test。此外,如果 url 是 /test?user=123 它必须被重定向到https://localhost/test?user=123或者如果 url 是 /test/test_db/user?id=123&pwd=123 必须是重定向到https://localhost/test/user/test_db/user?id=123&pwd=123

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

我如何在 apache 中使用 RedirectMatch 来实现这一点。我尝试了类似的东西

RedirectMatch permanent ^test/(.*)$ https://localhost/test/$1

这没有用。

4

2 回答 2

1

I wonder if this is better as a ServerFault question.

Anyway:
I don't know how you can achieve this with RedirectMatch, but I do know how you can do this with ModRewrite:

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

This is a fairly generic form that'll work for any HTTP Host (as I don't know any details about your host) and will redirect anything that matches with bla at the start of the URL and isn't already Https, with arguments and everything.

于 2012-03-21T04:39:37.123 回答
0

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

RedirectMatch 301 ^(/someprefix[^/]*/.*)$ https://hostname$1
于 2012-10-19T20:11:12.363 回答