WordPress.org

Support

Support » WP-Advanced » [Resolved] Writing a regex that excludes wp-admin

[Resolved] Writing a regex that excludes wp-admin

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

    [^[/wp\-admin]]*/(.*)/(.*)/(.*)\.php$
    and
    [^[/[w][p][-][a][d][m][i][n]]]+/(.*)/(.*)/(.*)\.php$

    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?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Kafkaesqui
    Member

    @kafkaesqui

    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.

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Writing a regex that excludes wp-admin’ is closed to new replies.