We have a two-months-old site with about 40 pages and 100 images. All of the URLs begin http://www.example.com/. We have just set up a new subdomain which we will use for all our URLs going forward, and I want to redirect all existing URLs to this new format.
So http://www.example.com/news would 301 redirect to http://subdomain.example.com/news for example.
To complicate it slightly, there are a few URLs we would like to remain accessible the old way, like http://www.example.com/system, http://www.example.com/cgi-bin, and a few others.
I believe there should be a straightforward way to do this with .htaccess such that all URL requests that begin with http://www.example.com are automatically 301 redirected to their counterpart URL beginning with subdomain.example.com.
I have tried the following, but it doesn’t seem to work (see the bottom chunk):
- Code: Select all
RewriteEngine on
# this is stuff that has to do with customizing our CMS, ExpressionEngine
RewriteCond $1 !^(cgi-bin|images|themes|uploads|vip|utilities|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
# this is what our host told us to add to setup the subdomain, so that it points to a subdirectory called subdomain
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain.example.com [NC]
RewriteCond %{REQUEST_FILENAME} !subdomain/
RewriteRule ^(.*)$ subdomain/$1 [L]
# THIS IS THE REDIRECT CODE I HAVE BEEN TRYING
RewriteBase /
RewriteCond $1 !^(cgi-bin|themes|uploads|utilities|system)
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/(.*)$ http://subdomain.example.com/$1
But this isn't working. Firefox tells me it detected a redirection infinite loop. Can anyone help?