Using a .htaccess Redirect
Need to do some development work on a website or CMS and want to work on it in the root directory while the old site continues to function?
- Create a new directory in the
public_htmlfolder and transfer the old website pages into it. - Next (if it doesn't already exist) create a text file named
.htaccessand paste in the below code and edit in your own IP addresses, domain name and the directory name (where your old site sits) and upload via FTP into yourpublic_htmlfolder:
RewriteEngine On
RewriteCond %{REMOTE_HOST} !^50\.104\.245.177
RewriteCond %{REMOTE_HOST} !^78\.517\.456.812
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/oldsite/
RewriteRule ^(.*)$ /oldsite/.
(You can delete line 3 if you don't need a second IP address, or just add additional lines of other IPs as needed.)
- Now test your site and make sure all the public traffic clicking on your links is being
redirected properly into the
oldsitedirectory (or wherever your old site sits), while your own IP address is being allowed access to the root directory where you can now start uploading and working on your new CMS or website. NOTE: You may need to edit your.htaccessfile occasionally if your ISP dynamically serves you your IP address. - After your new CMS or website is fully developed, tested and ready to go live, just remove or
comment out the script from the
.htaccessfile and let traffic access your new CMS/website. You can either keep theoldsitefolder as a backup or delete it completely once the new website is running smoothly.