0

我正在阅读它<Location '/'>实际上匹配整个域,而不仅仅是根位置。我想创建一个匹配除http://my.domain.com/Location之外的所有内容的或块,这意味着如果最后一个字符后面有任何字符,它将触发 '/LocationMatch

这是我将如何测试它:

<LocationMatch "REGEX GOES HERE">
    AuthType Shibboleth
    ShibRequireSession On
    Require Shibboleth
</LocationMatch>

我认为 Shibboleth 可能会改变一些行为。另请注意,我使用的是 Apache 2.2,但适用于 2.4 的解决方案也足够了。

4

1 回答 1

0

您可以使用LocationMatch此正则表达式:

<LocationMatch "^/.">

</LocationMatch>

Single DOT after^/将确保至少有一个字符,http://my.domain.com/因此导致它与登录页面不匹配。

有关更多详细信息LocationMatch

测试:

将此指令创建为:

<LocationMatch "^/(?<sitename>.+)">
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI}?u=%{env:MATCH_SITENAME} [L,R=302]
</LocationMatch>

现在测试我这样做:

curl -kI -A "Chrome" -L 'http://localhost/index.php'
HTTP/1.1 302 Found
Date: Mon, 11 Jul 2016 22:31:37 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1j PHP/5.6.9 mod_wsgi/3.5 Python/2.7.9
Location: http://www.localhost/index.php?u=index.php
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Mon, 11 Jul 2016 22:31:37 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1j PHP/5.6.9 mod_wsgi/3.5 Python/2.7.9
X-Powered-By: PHP/5.6.9
Content-Type: text/html; charset=UTF-8

curl -kI -A "Chrome" -L 'http://localhost/user.php'
HTTP/1.1 302 Found
Date: Mon, 11 Jul 2016 22:33:57 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1j PHP/5.6.9 mod_wsgi/3.5 Python/2.7.9
Location: http://www.localhost/user.php?u=user.php
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Mon, 11 Jul 2016 22:33:57 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1j PHP/5.6.9 mod_wsgi/3.5 Python/2.7.9
X-Powered-By: PHP/5.6.9
Content-Type: text/html; charset=UTF-8

curl -kI -A "Chrome" -L 'http://localhost'
HTTP/1.1 200 OK
Date: Mon, 11 Jul 2016 22:32:47 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1j PHP/5.6.9 mod_wsgi/3.5 Python/2.7.9
X-Powered-By: PHP/5.6.9
Content-Type: text/html; charset=UTF-8

您可以清楚地看到,当我请求登录页面时不会发生www重定向,而是在我请求时发生/index.php

于 2016-07-11T21:58:20.420 回答