Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect

         

fuzzy_vibes

1:04 pm on Oct 13, 2008 (gmt 0)

10+ Year Member



I'd like to create a .htaccess redirect in order to install a new cms.

While setting up the new cms all visitors except the Admin should be directed to the old one.
I guess there is a way to insert an IP based rule to a .htaccess file.

I am not that familiar with htaccess and need some help...

g1smd

3:37 pm on Oct 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, you can sniff the IP address of the visitor and redirect if it is not your IP. You can allow several IP addresses if it is likely that you will need access for more than one location.

Will any of the URLs for your content be changing in this migration? It is much better to keep the same URLs as before if you can.

There are many ways of achieving that.

If you cannot do so, it is vital that old URLs redirect to equivalent new URLs as soon as the new site goes live.

fuzzy_vibes

5:58 pm on Oct 13, 2008 (gmt 0)

10+ Year Member



I guess most of the URLs will change as we are planing to improve the structure of our site.
In this case it seems like redirecting the visitors temporarily is the easiest way to set up the new cms.

How can we achieve this using a .htaccess file?

securehotel

6:06 pm on Oct 13, 2008 (gmt 0)

10+ Year Member



if you know your own IP then allow that and Deny the rest . or put the cms in a sub folder while working on it

SteveWh

6:28 pm on Oct 13, 2008 (gmt 0)

10+ Year Member



Every situation is unique, so you'll have to adapt the code below and figure out where to fit the code into your existing .htaccess code, but it would look something like this. This would redirect your admins to the new site. Other requests would be unaffected, and go to the same destinations they always have.

RewriteEngine On
RewriteBase /
# PUT THE AUTHORIZED ADMIN IP ADDRESSSES IN THE LINES BELOW
RewriteCond %{REMOTE_ADDR} ^111\.222\.333\.444$ [NC,OR]
RewriteCond %{REMOTE_ADDR} ^111\.222\.333\.444$ [NC]
# THE ACTUAL CODE YOU USE FOR THE REDIRECT HERE WILL HAVE TO BE
# A LOT MORE COMPLICATED, DEPENDING ON WHETHER THERE ARE
# QUERY STRINGS IN THE URLS, WHERE YOU REALLY WANT TO GO, AND
# HOW THE OLD URLS MAP TO NEW ONES (IF AT ALL).
RewriteRule .* http://example.com/adminpage.php [R=301,L]

It is very unlikely that you can do this successfully without understanding the code, so the above is not posted as copy-and-paste. The intent is that you take the keywords and do web searches on them (see the Apache documentation at [httpd.apache.org...] ). Expect to spend a couple of days on it.

If you want to do a redirect when the IP address does NOT match the list of admin IP's:

RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.444$ [NC]
RewriteCond %{REMOTE_ADDR} !^444\.555\.666\.777$ [NC]

Note the added leading exclamation point, which means NOT.
This actually might be the form you'd end up using, based on your later comment that you want to redirect visitors (possibly to a static page that simply says, "Our website is down temporarily during a reorganization.") but allow yourself to work on the new site normally. This approach would be a lot easier. The following code is mostly copy-and-paste code to address that situation. It redirects all your visitors to sitedown.html, which you must create, saying the site is temporarily down.

#RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.444$
#RewriteCond %{REMOTE_ADDR} !^555\.666\.777\.888$
#RewriteCond %{REQUEST_URI} !^/sitedown.html$
#RewriteRule ^(.*)$ /sitedown.html [L]

There are other more complicated ways to handle this, as well, such as using a 503 error message, which is a more search engine friendly way to do it. However, since your reorganization is going to confuse search engines when it occurs, anyway, it may not be worth the trouble.

When you do the switchover, if you don't find a way to map old URLs to new ones, your site pages will lose all their search engine ranking status. The new pages will have to earn PageRank from scratch.

[edited by: SteveWh at 6:41 pm (utc) on Oct. 13, 2008]