WordPress.org

Support

Support » Plugins and Hacks » How do I implement conditions for wp_rewrite?

How do I implement conditions for wp_rewrite?

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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!

    [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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I implement conditions for wp_rewrite?’ is closed to new replies.
Skip to toolbar