Exclude directory from SEO redirect-rewrite

So if you change your WordPress permalinks from the default /p?=xxx format you will find that any extra directory or folder within your website no longer work. This is because of the RewriteEngine rules that WordPress uses within the root .htaccess file.

This was the default code after changing my permalink setup:

# 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

These 2 example lines exclude ‘Folder1’ & ‘Folder2’ from the rewriting rules and allows these folders to be used outside of the WordPress ecosystem.

RewriteCond %{REQUEST_URI} !^/(Folder1|Folder1/.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/(Folder2|Folder2/.*)$ [NC]

Put these together and we get:

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

Just remember that modifying the WordPress permalink configuration is likely to overwrite this and you will need to reimplement the changes.

Cheers

Comments are closed.