[resolved] Writing a regex that excludes wp-admin (3 posts)

  1. shacker
    Posted 8 years ago #

    The following rule keeps all of the old permalinks on a migrated publication site happy:

    RedirectMatch Permanent /(.*)/(.*)/(.*)\.php$ http://somedomain.net/$1/$2/$3

    Works perfectly for the public site, but unfortunately it breaks some plugins. I want to modify it to not take effect if the URL starts with /wp-admin. I've tried variants like these:


    but every attempt breaks the rule on the public site. Can anyone suggest a way to have an optional block at the start of the URL so that it won't affect the rest of the rule, and that will also not kick in when /wp-admin URLs are requested?

    Failing that, a workable solution with Rewrite instead of RedirectMatch?


  2. Kafkaesqui

    Posted 8 years ago #

    This two-liner with a RewriteCond work?

    RewriteCond %{REQUEST_URI} !^/wp-admin
    RewriteRule ^(.+)/(.+)/(.+)\.php$ http://somedomain.net/$1/$2/$3 [R=301,L]

    (You could try it with your RedirectMatch, but I'm unsure if RewriteCond works alongside it.)

    EDIT: Small changes to the regex stuff.

  3. shacker
    Posted 8 years ago #

    Thanks Kafkaesqui. I actually ended up taking a different approach. Rather than exclude wp-admin in .htaccess, I'm targeting the URLs I do want to rewrite more carefully.

    I was previously using this:

    RedirectMatch Permanent /(.*)/(.*)/(.*)\.php$ http://domain.net/$1/$2/$3

    but that was triggered by various plugins from inside wp-admin. Change that to this, matching year and date in first part of URL, and wp-admin is no longer affected:

    RedirectMatch Permanent /([0-9]*[0-9]*[0-9]*[0-9]*)/([0-9]*[0-9]*)/(.*)\.php$ http://domain.net/$1/$2/$3

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.