Make WordPress Core

Opened 6 years ago

Last modified 3 years ago

#43676 new defect (bug)

.htaccess rules don't work with Plain

Reported by: sebastianpisula's profile sebastian.pisula Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Rewrite Rules Keywords: has-patch
Focuses: Cc:

Description

If I use "Plain Url Style" in Permalink Settings then I can't add custom rules .htaccess from mod_rewrite_rules filter. I think that this is bug.

For example:

<?php
function uploads_from_remote_server( $rules ) {
        $rules = "<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule wp-content/uploads/(.*) http://example.com/wp-content/uploads/$1 [NC,L]
</IfModule>\n\n" . $rules;

        return $rules;
}

add_filter( 'mod_rewrite_rules', 'uploads_from_remote_server' );

This filter not working in Plain Url Style but should.

Attachments (1)

43676.patch (601 bytes) - added by sebastian.pisula 6 years ago.

Download all attachments as: .zip

Change History (4)

#1 @sebastian.pisula
6 years ago

  • Keywords has-patch added

This ticket was mentioned in PR #2114 on WordPress/wordpress-develop by ootwch.


3 years ago
#2

### Applies filter mod_rewrite_rules also when there are no permalinks.

There is a mod_rewrite_rules filter that perhaps many people don't know about, but it would be very helpful to control the .htaccess file, especially in a reverse-proxy scenario where the server does not have all the information to generate this correctly.

However, this filter is ignored when permalinks are not enabled. In practice this might not matter, but in setting up wordpress from scratch and/or in CI/CD scenarios this leads to unexpected behavior.

The fix is simple: Instead of exiting the function directly in the case of no-permalink only exit after applying the filter.

Trac ticket: https://core.trac.wordpress.org/ticket/43676

#3 @ootwch
3 years ago

Added a pull request (slightly different to the existing patch).

Note: See TracTickets for help on using tickets.