htaccess rewriterule. I don’t want all of them rewritten – How to exclude some pages?

My htaccess is as follows:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^moreinfo/(.*)$ http://www.kgstiles.com/moreinfo$1 [R=301]
    RewriteRule ^healthsolutions/(.*)$ http://www.kgstiles.com/healthsolutions$1 [R=301]
    RewriteRule ^(.*).html$ $1/ [R=301]
    RewriteRule ^(.*).htm$ $1/ [R=301]
</IfModule>

I am now using wordpress rather than straight html coding. The rewriterules above work to forward all of the old .html and .htm pages in the root directory and in /moreinfo/ and /healthsolutions/ directories. Unfortunately they also strip .htm and .html from wordpress pages (I thought they all ended in php initially). Now I see some of the basic functions like opening up the image editor in the visual editor of wordpress end in .html (using them produces a 404 error).

Read More

So the question is: is there any way to restrict my rewriterules to certain directories, so WordPress functions are not hindered?

Any help is appreciated!

Related posts

Leave a Reply

2 comments

  1. You can try something like this:

    RewriteEngine On

    # assuming wordpress is installed in blog directory
    RewriteRule ^blog(/.*|)$ - [L] # don't take any action
    
    RewriteRule ^moreinfo/(.*)$ http://www.kgstiles.com/moreinfo$1 [R=301,L]
    RewriteRule ^healthsolutions/(.*)$ http://www.kgstiles.com/healthsolutions$1 [R=301,L]
    RewriteRule ^(.*).html$ $1/ [R=301,L]
    RewriteRule ^(.*).htm$ $1/ [R=301,L]
    

  2. You need to add a Rewrite condition, such as this:

    RewriteCond $1 !^(dontrewrite.php)
    

    You can add RegEx expressions in there to omit certain directories/folders/filetypes.