Access old site after redirection

1.9k views Asked by At

I need to do permament redirect from clients old site to new one, redirection is from hissite.eu to newsite.com, same hosting but other domains. Now, he wants to still have access to his old site via some subdomain which would not be problem if i could make it work, but old site was badly made with custom CMS, lots of hardcoding and it just does not work if i move it to any directory.

So my question is if i make permament redirection from oldsite.eu to newsite.com , how can i provide him with access to his old site ? Is it possible somehow to not redirect if he types ip address instead of domain, but i suppose again administration panel wouldnt work. Is it possible to do redirection on everyone except specific ip maybe ?

Updating with current htaccess:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Rewriterule ^index$                             index.php [L]
Rewriterule ^login$                             login.php [L]
Rewriterule ^register$                          register.php [L]
Rewriterule ^classified_new$                        classified_new.php [L]
Rewriterule ^account_classifieds$                   account_classifieds.php [L]
Rewriterule ^account_classifieds_manage$                account_classifieds_manage.php [L]
Rewriterule ^account_confirm$                   account_confirm.php [L]
Rewriterule ^account_details$                   account_details.php [L]

Rewriterule ^account_invoice_browse$                account_invoice_browse.php [L]
Rewriterule ^account_invoice_details$               account_invoice_details.php [L]
Rewriterule ^account_main$                      account_main.php [L]
Rewriterule ^account_messages$                  account_messages.php [L]
Rewriterule ^account_profile$                   account_profile.php [L]
Rewriterule ^ajax_request$                      ajax_request.php [L]
Rewriterule ^classified_browse$                     classified_browse.php [L]
Rewriterule ^classified_details$                    classified_details.php [L]
Rewriterule ^classified_new_form$                   classified_new_form.php [L]
Rewriterule ^classified_new_premium$                classified_new_premium.php [L]
Rewriterule ^classified_payment$                    classified_payment.php [L]
Rewriterule ^classified_new_confirmation$           classified_new_confirmation.php [L]
Rewriterule ^classified_payment_process$                classified_payment_process.php [L]
Rewriterule ^classified_payment_response$           classified_payment_response.php [L]
Rewriterule ^classifieds_json$                  classifieds_json.php [L]
Rewriterule ^convert$                           convert.php [L]
Rewriterule ^help$                          help.php [L]
Rewriterule ^login_process$                         login_process.php [L]
Rewriterule ^search_advanced$                   search_advanced.php [L]
Rewriterule ^verification_image$                    verification_image.php [L]

#search result
Rewriterule ^search/(.*)$ search_results.php?q=$1 [L]

#classified detail
Rewriterule ^classified/(.*)$ classified_details.php?id=$1 [L]
</IfModule>
3

There are 3 answers

10
Prix On BEST ANSWER

It is possible to redirect all but a given IP, you can add a condition to your redirect for example:

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [R=301,L]

For multiple IP's:

RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [R=301,L]

Or if the IPs have the same block 192.168.0.1, 192.168.0.2, 192.168.0.3:

RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [R=301,L]

Change xxx\.xxx\.xxx\.xxx to your client IP.

However this would give you a few issues, for instance:

  1. you client could have cached the redirect already, so you would need to ask him to use a different browser temporary or clear his cache (which doesn't always work).

  2. If you have deleted the old rules it possible had on the .htaccess it would not work as expected.

  3. if your client have dynamic IP you would need to change that every time he tries to access it.

There is probably more but this are the most common.

0
hakre On

Is it possible to do redirection on everyone except specific ip maybe ?

Yes, that is perfectly possible. And I actually suggest you to do it that way because it is most easy to use. Alterantively you can also look for specific request headers so that the customer can view the old or new site and can control that. Another way is with cookies.

Now in concrete this is done depends a bit on the concrete webserver you're using, but most webservers are able to handle such configurations.

E.g. if you're using Apache HTTPD with mod_rewrite based redirects, you can formulate a RewriteCond accordingly.

4
anubhava On

One simple way of achieving this is by passing a secret query parameter by your client: (you can make it more complex as needed)

# set a cookie only if a secret URL e.g. http://oldsite.eu?q=q1w2e3r4t5
# is passed
RewriteCond %{QUERY_STRING} (^|&)q=q1w2e3r4t5(&|$) [NC]
RewriteRule ^ - [L,CO=mredir:0:secret]

# if cookie isn't set then redirect to new website
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.eu$ [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [R=301,L]

EDIT

Looked at your .htaccess and I would strongly suggest you to combine your multiple Rewriterule lines. See an example below:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Rewriterule ^(index|login|register|help)$ $1.php [L,NC]