[wp-trac] [WordPress Trac] #47466: Add a comment to .htaccess markers, labelling inserted strings as read-only/ dynamic

WordPress Trac noreply at wordpress.org
Mon Jun 3 12:44:49 UTC 2019


#47466: Add a comment to .htaccess markers, labelling inserted strings as read-
only/ dynamic
---------------------------+-----------------------------
 Reporter:  bradleyt       |      Owner:  (none)
     Type:  enhancement    |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Rewrite Rules  |    Version:
 Severity:  minor          |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 When using WordPress on an Apache server, with pretty permalinks enabled,
 WordPress will write `rewriteRule` directives to the .htaccess file in
 order to allow the pretty permalink functionality. On an out-the-box
 WordPress installation this will look like so:


 {{{
 # BEGIN WordPress
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
 # END WordPress
 }}}

 This inserted block is wrapped in `BEGIN WordPress`/ `END WordPress`
 comments, referred to as markers. WordPress then uses these markers in
 order to update the correct part of the .htaccess file if the htacess file
 needs to be rewritten.

 I work for a development company, who host a number of WordPress and non-
 WordPress sites. We frequently need to make changes to the htaccess file,
 which we generally do outside of WordPress (i.e. by directly editing the
 file). For example, we often add HTTP redirects via the htaccess file.
 Often the sysadmins who make these changes are not familiar with
 WordPress, and insert their custom rules within the `BEGIN WordPress`/
 `END WordPress` markers, assuming that any WordPress-related rules should
 go between these comments. These custom changes are then discarded by
 WordPress at a later date, when the rewrite rules are next flushed.

 I propose that additional comments are added to the htaccess file, to make
 it clear the the contents of the markers should only be edited via the use
 of WordPress filters.

 For example:

 {{{
 # BEGIN WordPress
 #
 # The directives (lines) between `BEGIN WordPress` and `END WordPress` are
 dynamically generated,
 # and should only be modified through the use of WordPress filters.
 # Any changes to the directives between these markers will be overwritten.
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
 # END WordPress
 }}}

 It's worth noting that some plugins also use `insert_with_markers`, and so
 this should be returned with the correct marker name for any use of
 `insert_with_markers`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47466>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list