Why doesn’t the Apache LocationMatch directive work

apache-2.4cobbler

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.

Best Answer

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]
Related Topic