mod_rewrite To Redirect everything within a directory except for the directory itself

I’m going to be using WordPress as a new CMS for my site, and will be using the permalinks for many of the pages. The problem is there are many old pages and files outside of WordPress that need to remain within directories that overlap with the permalinks. For example, a permalink for a WP page would be at:
http://www.domain.com/support/

But I have several php apps and other files that people still use within the /support/ directory that need to be accessed by the same URLs. If there is a directory in the same place as the permalink then the permalink is ignored.

Read More

I’ve been researching this and found that I can probably rename the physical directory (to “A-support”, for example), and then redirect everything except for a url pointing to the exact directory to the new location.

So this should not redirect:
http://www.domain.com/support/

But all of these should redirect to the new /A-support/ directory location:
http://www.domain.com/support/page.html
http://www.domain.com/support/subdirectory/
http://www.domain.com/support/subdirectory/page.html

Here is the .htaccess rule I have so far that doesn’t seem to be working, as it will simply redirect everything to directly within the /A-support/ folder, and not work for subdirectories:

RewriteCond %{REQUEST_URI} support/(.+)$
RewriteCond %{REQUEST_URI} !support/(.+)/$
RewriteRule ^support/(.+)$ http://www.domain.com/A-support/ [L]

I’ve looked at the docs but it’s a relatively confusing function for me and I can’t seem to get it right.

Thank you for any help!

Related posts

Leave a Reply

1 comment

  1. Try this instead:

    RewriteRule ^support/(.+)$ http://www.domain.com/A-support/$1 [L]
    

    The main thing that you’re missing is the $1 backreference. This shouldn’t redirect /support/ and only anything within it. You don’t need any of the other conditions.