Dynamic .htaccess URL Redirects to Subfolders

Avatar
  • Answered
I have a website with Wordpress installed in a subfolder (i.e. www.mydomain.com/wordpress). Currently, I've an .htaccess file in the top folder that redirects all traffic from "www.mydomain.com" to "mydomain.com/wordpress". However, my organization also puts out a print publication that requires us to print URLs that are as short and verbose as possible, such as "mydomain.com/news" or "mydomain.com/culture". How can I have the server redirect from "mydomain.com/foo" to "mydomain.com/wordpress/foo"? "foo" in this case could be anything: this is the "dynamic" part of my question; I don't know what redirections will be needed in the future, and I'd rather not have to edit the .htaccess file for every situation we encounter.
Thanks in advance!
Avatar
JeffMa
This can be acheived quite easily within your .htaccess file. Place the following into your root directory's .htaccess:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?(.*) http://www.example.com/wordpress/$1 [R=301,L]

Of course, edit the last line to reflect your domain.