wp-h5bp-htaccess icon indicating copy to clipboard operation
wp-h5bp-htaccess copied to clipboard

Placement of Directives

Open VR51 opened this issue 9 years ago • 5 comments

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.

VR51 avatar May 19 '15 20:05 VR51

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.

QWp6t avatar May 19 '15 23:05 QWp6t

Will test at some point during the the next fortnight.

Thanks again.

VR51 avatar May 21 '15 14:05 VR51

@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);

bryanwillis avatar Apr 08 '16 02:04 bryanwillis

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.

QWp6t avatar Apr 08 '16 03:04 QWp6t

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?

VR51 avatar Apr 25 '16 20:04 VR51