1

I need help getting apache's LocationMatch to work.

I'm trying to set up a cobbler server, and it requires SSL by default. I want to rewrite so that people can use http://server/cobbler_web instead as well as the https://server/cobbler_web, and it will bring them to the same page. I am trying to use LocationMatch to match cobbler_web in the URL, like so:

### Force SSL only on the WebUI
<VirtualHost *:80>
    <LocationMatch "^/cobbler_web/">
       RewriteEngine on
       RewriteRule ^(.*) https://%{SERVER_NAME}/%{REQUEST_URI} [R,L]
   </LocationMatch>
</VirtualHost>

but no matter what I try on the LocationMatch line, nothing works. I've tried the line you see above, and also .*cobbler_web.*, and ^/cobbler_web/.*, amongst others. No joy.

If I remove the LocationMatch entirely, it works.

Thanks.

Mike S
  • 1,145
  • 5
  • 22
  • 42

2 Answers2

1

If you're turning on the rewrite engine anyway, just use that to match the location:

   RewriteRule ^/cobbler_web/ https://%{SERVER_NAME}/%{REQUEST_URI} [R,L]
Josip Rodin
  • 1,695
  • 13
  • 18
  • That didn't work. Neither did this: `RewriteRule "^/cobbler_web/" https://%{SERVER_NAME}/%{REQUEST_URI} [R,L]` . I got "403 Forbidden" results. – Mike S Dec 04 '15 at 22:40
  • Just to make sure, you removed the LocationMatch block, right? Anyway, 403 could be generated from a number of reasons, you need to have a look at the error log, and also enable mod_rewrite log and see what's going on. – Josip Rodin Dec 06 '15 at 21:39
  • Yes I removed the LocationMatch block. To be clear: Put it in, fail. Take it out, success. It is as simple as that... for me. I will look at the logs you suggest. I didn't see anything useful in the error log but I'll check again. – Mike S Dec 08 '15 at 00:07
0

Not sure why this configuration doesn't work, but in this simple case plain old <Location "/cobbler_web/"> should be enough.

sam_pan_mariusz
  • 2,133
  • 1
  • 14
  • 15