Home » WordPress

Add Custom Rules to WordPress .htaccess

December 5, 2007

WordPress uses a .htaccess file to rewrite all the URLs to look like “http://www.kingrosales.com/category/internet-marketing/” rather than “http://www.kingrosales.com/index.php?pageid=10″.

By default, a WordPress .htaccess file looks like:


# BEGIN wordpress
<ifmodule mod_rewrite.c>
rewriteEngine On
rewriteBase /
rewriteCond %{REQUEST_FILENAME}!-f
rewriteCond %{REQUEST_FILENAME}!-d
rewriteRule . /index.php [L]
</ifmodule>
# END wordpress

When I had to install a custom application under a non-wordpress directory and wanted to rewrite those URLs, I would always get a “Error 404 – Page Not Found” from WordPress & any custom non-wordpress related rules I was writing wouldn’t work.

Solution:

If you want to add custom .htaccess non wordpress rules, simply enclose your custom rules between a new “<ifmodule mod_rewrite.c>…</ifmodule> and have it positioned above the exisiting WordPress rules:

# My Custom Rules
<ifmodule mod_rewrite.c>
rewriteEngine On
... Your Custom Rules Here...
</ifmodule>
# End Custom Rules
# BEGIN wordpress
<ifmodule mod_rewrite.c>
rewriteEngine On
rewriteBase /
rewriteCond %{REQUEST_FILENAME}!-f
rewriteCond %{REQUEST_FILENAME}!-d
rewriteRule . /index.php [L]
</ifmodule>
# END wordpress

And that’s it! Happy Rewriting :)

Share This Post!


subscribe to my blog via rss subscribe to my blog via email

About the Author

King Rosales works as an Internet Marketing Professional in Calgary, Alberta, Canada for an E-Commerce company where he focuses on conversions via PPC, email campaigns and social media (social commerce).

Related Posts

4 Comments »

  • Irwan said:

    Could you please give me an example custom htaccess code for adding non wp directory?

    I’ve tried but still have 404 error

  • Sean said:

    This does not work – 404 page is always returned

  • Derek said:

    def. didnt’ work.

  • Henry said:

    Like the others, this also DIDN’T work for me.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

ClickHeat : track clicks