Add Custom Rules to WordPress .htaccess

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 put the wordpress rules after all your other 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 🙂

Tags

Leave a Reply

Your email address will not be published.

top