1. Change any URL from the old domain to the new domain. That includes "forums.old.com/blah" to "forums.new.blah"
2. When the URL has no subdomain, it changes the "root" to a subdirectory. That means just plain ol' "new.com" or "www.new.com" points to "new.com/something". But if there is a subdomain, then...
3. Subdomains point to subfolders. "blah.new.com" points to "new.com/blah" But I want the subdomain to still be shown in the address bar.
The problem is getting these three rules to work together. I'dd admit, I don't know jack shit about mod_rewrite, my only hope is to just find snipplets online and copy/paste them. Here is what I have already:
- Code: Select all
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
Options +FollowSymLinks
RewriteEngine on
##### domain change
RewriteCond %{HTTP_HOST} ^(.*)dol-domain.net [NC]
RewriteRule ^(.*)$ http://new-domain.in/$1 [R=301,L]
##### change to the /logbook folder
RewriteRule ^$ /logbook/ [QSA,L]
RewriteCond %{HTTP_HOST} ^(www.)?new-domain\.in$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^logbook(/.*)?$ /logbook%{REQUEST_URI} [QSA,L]
######subdomain to subfolder
# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} !^(www\.)?new-domain\.in$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.new-domain\.in$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?new-domain\.in$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.new-domain\.in$ [NC]
RewriteRule ^(.*)$ /%2/$1 [QSA,L]
Each chunk of code works perfectly together, but when you have all three of them in there, they conflict with each other and end up not working. If you wane to see how this is working, follow the following links:
http://old-domain.net
http://new-domain.in
http://old-domain.net/logbook
http://new-domain.in/logbook
http://forums.old-domain.net
http://forums.new-domain.in
http://old-domain.net/forums
http://new-domain.in/forums