[wp-docs] Added user page on .htaccess file generation, feedback?

Otto otto at ottodestruct.com
Wed Aug 31 17:09:03 UTC 2011


BTW, you did get very close to this there at the end. What you missed
was that the add_rewrite_rule function (not the class function, but
the normal one), makes the resulting call to add_rule in the class.
This then does the index.php based determination, and adds the rule to
the $non_wp_rules there.

No need for an action on generate_rewrite_rules. That's the hard way
to do it. Put your action on init, then just call the add_rewrite_rule
function normally.

-Otto



On Wed, Aug 31, 2011 at 12:03 PM, Otto <otto at ottodestruct.com> wrote:
> You missed a rather simple trick that not many people know about. This
> will add a rule to the .htaccess file when the rules are hard flushed.
>
> add_rewrite_rule('myrule', '/newlocation');
>
> In WordPress, all "internal" rewrite rules must start with "index.php"
> for them to work properly. Any rule that doesn't start with index.php
> gets shoved out into the .htaccess file as a normal RewriteRule when
> the flush happens (basically when you visit the Settings->Permalink
> page).
>
> So you can use normal add_rewrite_rule calls to add normal .htaccess
> rules as well as the internal kind.
>
> Note: Internal rules use the $matches[1] method for referencing
> pattern matchers. This won't work in .htaccess rules, you have to use
> the $1 method for those rules.
>
> -Otto
>
>
>
> On Wed, Aug 31, 2011 at 11:33 AM, David Miles <amereservant at gmail.com> wrote:
>> Hey everyone,
>> I recently dove into trying to utilize WordPress's rewrite engine and how to
>> add content to the .htaccess file indirectly.
>> I discovered the first part wasn't too complicated once I read over a few
>> tutorials, but modifying/adding to the .htaccess file was a whole different
>> story.
>> So I decided to take a few hours and write some (hopefully helpful)
>> information to help
>> others, http://codex.wordpress.org/User:Amereservant/Editing_and_Customizing_htaccess_Indirectly
>> I'm sure there's things I've missed or perhaps some of you have more
>> advanced knowledge of the topic and can refine the information to be more
>> useful.
>> Either way, I'd love to hear feedback on it and what you think.
>> Thanks,
>>
>> David
>> _______________________________________________
>> wp-docs mailing list
>> wp-docs at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-docs
>>
>>
>


More information about the wp-docs mailing list