Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about RewriteOptions Inherit #337

Open
jamieburchell opened this issue Jan 12, 2023 · 3 comments
Open

Add note about RewriteOptions Inherit #337

jamieburchell opened this issue Jan 12, 2023 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@jamieburchell
Copy link
Contributor

jamieburchell commented Jan 12, 2023

If you use the h5bp Apache config in a server configuration, and add a virtual host and a directory block with custom rewrite rules, none of the h5bp rewrite rules will work. This is because the new rewrite rules overwrite existing ones by default.

Do you think it's worth mentioning this anywhere?

E.g.

Let's say you have this (taken from h5bp) in your main config file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
</IfModule>

You then create a virtual host configuration:

<VirtualHost *:80>
    ServerName example.com
    # ...
    <Directory /var/www/httpdocs/>
        RewriteEngine On
        # Without inheritance of rewrite rules, none of the h5bp rules take effect :(
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </Directory>
</VirtualHost>

For blocking access to hidden files I prefer to use Require all denied with a LocationMatch, but this is just an example.

It strikes me that it's not immediately obvious that the rules from h5bp have no effect in certain situations. At least, it wasn't to me.

Ref: https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions

@LeoColomb
Copy link
Member

Thanks for opening this issue @jamieburchell.
What about adding the following directive to the H5BP rewrite block?

RewriteOptions InheritDown

@jamieburchell
Copy link
Contributor Author

My concern would be that it has the potential to break existing configurations since it then becomes necessary to explicitly ignore inheritance where it would have been the default behaviour.

@LeoColomb
Copy link
Member

Indeed, you are right.
Then yes, a commented out directive with a line or two docs would make sense in virtual host config templates. 👍

@LeoColomb LeoColomb added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 22, 2023
@LeoColomb LeoColomb changed the title Add note about RewriteOptions Inherit ? Add note about RewriteOptions Inherit Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants