9

I have a pretty standard WordPress .htaccess with the following URL rewrites

# BEGIN WordPress 
<IfModule mod_rewrite.c>  
RewriteEngine On  
RewriteBase /  
RewriteRule ^index\.php$ - [L]  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule . /index.php [L]  
</IfModule> 
# END WordPress  

WordPress is installed in my domain root. I have some other scripts in subfolders, e.g. /opencart These subfolders contain their own .htaccess files.

Unfortunately, it seems that WordPress hijacks the rewrites for some of these scripts sometimes.

How can I ask mod_rewrite to ignore WordPress rules for rewrites when encountered with specific subfolders e.g. opencart and to use the rules defined in the .htaccess within these subfolders instead?

3 Answers 3

27

You may try replacing the complete WP rule-set with this one:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(folder1|folder2|folder3) [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress 
3
  • Suggestion MIGHT be correct but am not getting results as WordPress keeps overwriting .htaccess, removing RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC] which is really the relevant part of the suggested rule set.
    – OC2PS
    Mar 8, 2013 at 17:08
  • That's another problem and it's pretty odd indeed, WP normally updates that file only at install time. Check the Plugins, maybe some one is doing that and disable all of them to test. Also check wp-config to make sure a line like this one define('RELOCATE',true) is not there. If so, delete it. Mar 8, 2013 at 19:04
  • 1
    I'm going to accept this answer though it didn't work for me. In my case the problem turned out to be something entirely different and required a very different approach than I presumed in the question.
    – OC2PS
    Mar 9, 2013 at 13:47
10

In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
-1
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^/(folder1)/(.*) /folder1/$2 [R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L,R]

</IfModule>

# END WordPress

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.