WordPress.org

Ready to get started?Download WordPress

Forums

How do I implement conditions for wp_rewrite? (3 posts)

  1. SocialBlogsite
    Member
    Posted 2 years ago #

    I need a non-wp re-write rule to be installed by wp for my plugin.

    it should help a series of files to be found by the client even when requested to be in the wrong location. Kind of an application being found in your computer.

    E.g. Given the file to be found will be always at:

    http://www.mydomain.com/here/findme1.html
    http://www.mydomain.com/here/findme2.html

    I need to test whether the url contains "here/findme" and return the right url if it doesn't.

    Such incorrect request is not fixable, so moving on, I have created a redirect rule that needs to be added to .htaccess by wp the first time the plugin is run.

    How do I tell wp to add the conditional before the rule?

    It should write in .htaccess the following:
    (I ignore how in Windows server. I'll research how wp manages redirections in windows)

    RewriteCond %{REQUEST_URI} !here
    RewriteRule ^.*findme(.*)$ /here/findme$1 [R=301,L]

    Thanks.

  2. SocialBlogsite
    Member
    Posted 2 years ago #

    Ok, I found a way to include a conditional in a WP_Rewrite the way WP accepts it, i.e.

    pattern => substitution

    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule ^.*(?!_here)/*findme\.html$ /_here/findme.html [R=301,L]

    But that enters in an infinite loop. No other code is in the .htaccess file, so it's conflicting with itself.

    why!!!?

    help!

  3. SocialBlogsite
    Member
    Posted 2 years ago #

    [UPDATE]

    I've made lazy the first dot, but still loops.

    RewriteRule ^.*?(?!_here/)findme\.html$ /_here/findme.html [R=301,L]

    Could it be affected by the replacement starting with / which makes the server to re-write it include the domain name?

Topic Closed

This topic has been closed to new replies.

About this Topic