1

I'm reading that <Location '/'> actually matches the entire domain, not just the root location. I want to create a Location or LocationMatch block that matches everything but http://my.domain.com/ This means it will trigger if any characters follow that final '/

Here is how I will be testing this:

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

I think Shibboleth may change some behavior. Also note I am using Apache 2.2 but a solution that works on 2.4 will suffice as well.

jlewkovich
  • 2,725
  • 2
  • 35
  • 49

1 Answers1

1

You can use LocationMatch with this regex:

<LocationMatch "^/.">

</LocationMatch>

Single DOT after ^/ will make sure there is at least one character after http://my.domain.com/ hence causing it to not to match landing page.

More details about LocationMatch

Testing:

Create this directive as:

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

Now to test I am doing this:

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

You can clearly see that www redirection doesn't happen when I request landing page but happens when I request /index.php

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • This is triggered on root as well...I've added some clarification on how I'm testing this, perhaps Shibboleth changes behavior – jlewkovich Jul 11 '16 at 22:03
  • I've added testing information to show how this directive is working fine – anubhava Jul 11 '16 at 22:34
  • I am now testing with `Header set X-TEST-ME "TESTING"` and it is appearing on all URLs...I think you may be solving this partially by using RewriteRules, I am hoping for a cleaner solution – jlewkovich Jul 11 '16 at 23:35
  • No I am not. `RewriteRules` is just a way to test whether `LocationMatch` is being applied to landing page or not and from above test it is clear that same redirect is not happening for landing page only. – anubhava Jul 12 '16 at 03:58
  • btw if you are on Apache 2.4 then you don't even need to handle this via `Location` directive which is only allowed in Apache/vhost config but not in .htaccess – anubhava Jul 12 '16 at 11:59