Home  »  Solutions  »  What I've Learned  »  Override Wordpress Htaccess with Custom Rewrite Rules

Override Wordpress Htaccess with Custom Rewrite Rules

Nate Weiner - Posted in What I've Learned, , , , Comments (4)

I was working on a client project that used Wordpress as it’s main method for content management.  In addition to Wordpress, it had a seperate admin/member area hosted on the same domain.  In this member area I had implemented several uses of Mod Rewrite to make cleaner urls.

However, when Wordpress was installed it’s htaccess rules took over request, no matter what I had entered and in what order.

Here what my htaccess file looks like to allow other rewrite rules to run side by side with Wordpress:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(file|member|photo) [NC]
RewriteRule . /index.php [L]

RewriteRule ^member/([0-9]+)/ /member_profile.php?m=$1
RewriteRule ^file/([0-9]+)/(.+)? /file.php?f=$1
RewriteRule ^photo/([^/]+)/([^/]+)/(.+)? /file.php?type=$1&ref_id=$2&photo=1

</IfModule>

By adding the Rewrite Condition with Request URI, I’m able to add rules/folders that Wordpress should ignore.  Make sure you use Request_URI and not Request_Filename.  They provide two different results.

Comments (4)


  1. Hi!
    I have photoblog software (Pixelpost) installed in my root, so my /index is allready occupied
    My WP is installed in mysite/blog/
    Now I want the WP about page to be re-written to:
    mysite/about/

    I tried setting up an .htaccess file in the root with:
    RewriteRule ^about(.*)$ blog/?page_id=203$1 [L,NC]

    This works, but pulls to:
    mysite/blog/about/
    because interfears with WordPress? .htaccess (I use the pretty permalinks)
    I tried adding the rewrite rule outside the # BEGIN WordPress - # END WordPress block but no luck.

    Looking at your URI’s you clearly know how to do this, rewrite Wordpress content outside the install dir.
    I tried your Request_URI rewrites, but keep on failing.
    Your .htaccess example code, where did you place this? In the root? Above or under # WordPress # rewrite rules?

    Can you help me?
    My code in mysite/blog/.htaccess looks like this:

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    # END WordPress

    January 2nd, 2009 Anton
  2. Thank you so much for posting this. It was a TREMENDOUS help!

    May 5th, 2009 Ian
  3. You don’t know how much I needed this, thanks for the post! I was getting really frustrated over why my rules were being ignored. Wordpress should include a documentation page on this (or make it easier to find).

    October 17th, 2009 Sunny Singh
  4. This is fantastic! Thank you so much! Have you been able to get this to work with Wordpress Permalinks? Evidently there are some flags within WP that cause this not to work if the setting within Permalinks is anything other than Default (even with replacing Wordpress’s htaccess details).

    November 26th, 2009 Brett

Leave a Reply