Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Placement of Directives #16

Open
VR51 opened this issue May 19, 2015 · 5 comments
Open

Placement of Directives #16

VR51 opened this issue May 19, 2015 · 5 comments

Comments

@VR51
Copy link

VR51 commented May 19, 2015

Shouldn't the boilerplate .htaccess directives go before the WordPress ones?

.htaccess being processed top-to-bottom, when the WordPress directives are placed earlier than the H5BP directives it means the H5BP directives are processed too late i.e. after WordPress has already processed requests.

@QWp6t
Copy link
Member

QWp6t commented May 19, 2015

It's literally the first line of code.

add_action('generate_rewrite_rules', __NAMESPACE__ . '\\ApacheServerConfig::init', -9999, 0);

There's not much else that I know of that I can do besides set it to the lowest priority like that so that it hopefully gets processed first.

I have noticed that sometimes it's not first, and I'm not sure why, but I also didn't care. WordPress only has rewrite rules, so this really isn't that big of a deal, imo.

If you want to give it a shot and send a PR, feel free.

@VR51
Copy link
Author

VR51 commented May 21, 2015

Will test at some point during the the next fortnight.

Thanks again.

@bryanwillis
Copy link

@QWp6t you might be able to use PHP_INT_MIN if you want to make sure the priority is as low as possible.

add_action('generate_rewrite_rules', __NAMESPACE__ . '\\ApacheServerConfig::init', PHP_INT_MIN, 0);

@QWp6t
Copy link
Member

QWp6t commented Apr 8, 2016

That's only for PHP 7.0+.

But it's not absolutely necessary to be the very first, so I'm not concerned about that.

@VR51
Copy link
Author

VR51 commented Apr 25, 2016

It is necessary to be first for some of the directives to be effectual.

.htaccess is read from top to bottom and directives are observed in read-order. Once the WordPress rewrites are reached, WordPress takes over for virtual files and directories that are managed by WP and thus applies WP PHP based rewrites.

For example, where we want to deny access to a file or directory, if WP kicks in before the .htaccess directive that blocks access to a document that is read by Apache then that directive might not be observed in time to prevent the document being served.

Another example, the directives that gzip output are best placed at the top of .htaccess so they take effect immediately and not after the files have already been served.

Placement does matter.

Maybe prepend the directives to htaccess and include DirectoryIndex at the top?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants