Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-07-2009, 10:50 PM   PM User | #1
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
.htaccess redirect everyone but my IP

Hey everyone,

I recently moved my site from http://www.tutorialwow.com/ to http://www.tutwow.com/. On the old site, I put this in the htaccess:

Code:
Redirect / http://www.tutwow.com/
That redirected everyone (including me) to the new domain. The important thing is that it took everything on the end of the old URL and pasted it onto the new one. For example, if the user went to http://www.tutorialwow.com/contact/, they would get redirected to http://www.tutwow.com/contact/ instead of just http://www.tutwow.com/.

My question is this - is there any way to redirect everyone to the new domain (just like in the code above) except for my IP? Is there some conditional statement that I can use?

Thanks!

Ben
BlindSeeker is offline   Reply With Quote
Old 04-08-2009, 12:01 AM   PM User | #2
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
i know you can achieve this with php if that helps. Not sure about apache. Here is the php code regardless.

PHP Code:
if (!$_SERVER['REMOTE_ADDR']="84.63.49.192"// Replace with your IP
     
header('Location: http://www.tutwow.com'); 
That would go at top of page.

Anther solution would be to add http://www.tutorialwow.com as a server alias to http://www.tutwow.com/ which would take /contact/ and everything. Though the URL would still look like the old one but would actually be on the new site. Or setting up both virtual hosts document root to the same location. Either way then you could set up a new subdomain for the old site. Then using htaccess to only allow your IP to access that subdomain.
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-08-2009, 12:15 AM   PM User | #3
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Thanks for the speedy reply!

However, I think I can only use htaccess because I can't put PHP on every page on the site. The thing is, I just need to be able to access the site while other people are being redirected. Isn't there some conditional statement in htaccess?
BlindSeeker is offline   Reply With Quote
Old 04-08-2009, 01:40 AM   PM User | #4
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Not that i am aware of. I think setting up a subdomain is the quickest.
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-08-2009, 09:47 PM   PM User | #5
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
How would making a subdomain help? The Redirect command redirects everything, including subdomains.
BlindSeeker is offline   Reply With Quote
Old 04-09-2009, 12:22 AM   PM User | #6
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Not if you put the redirect rule in the apache conf file for that virtual host.

Code:
 <VirtualHost 111.22.33.44>
    ServerName www.domain.tld
    ...
    Redirect / http://www.new-domain.com/ 
    </VirtualHost>
    
    <VirtualHost 111.22.33.44>
    DocumentRoot /www/domain
    ServerName www.sub.domain.tld
    ...
    </VirtualHost>
__________________
You can not say you know how to do something, until you can teach it to someone else.

Last edited by timgolding; 04-09-2009 at 12:29 AM..
timgolding is offline   Reply With Quote
Old 04-09-2009, 03:22 AM   PM User | #7
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Wow, my web host doesn't allow the virtualhost thing. Quite annoying! Any other ways I could do it?
BlindSeeker is offline   Reply With Quote
Old 04-09-2009, 09:41 AM   PM User | #8
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
There is another way you can use IP blocking with your htaccess that will give a 403 error if the user is not on the IP secified. Then rather than using the standard 403 document you can redirect them to a different one with the following command.

Code:
ErrorDocument 403 /newerrordoc.html
Then in that page 'newerrordoc.html' you can put an html redirect command

Code:
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com">
Oh here's the IP blocking htaccess code

Code:
<Limit GET POST>
order deny,allow
deny from all
allow from 111.22.33.44
</Limit>
Another alternative would be looking into using apache mod rewrite. If the above method doesn't work i'll look into that for you.
__________________
You can not say you know how to do something, until you can teach it to someone else.

Last edited by timgolding; 04-09-2009 at 09:45 AM..
timgolding is offline   Reply With Quote
Old 04-09-2009, 04:49 PM   PM User | #9
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Ok, that worked! Finally found a solution.

Thanks for all the help!
BlindSeeker is offline   Reply With Quote
Old 04-15-2009, 09:08 PM   PM User | #10
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
You can do it with mod_rewrite
Code:
Options +FollowSymLinks

RewriteEngine On

# If it's not your IP address
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
# Redirect /abc to example.com/abc.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
schleppel is offline   Reply With Quote
Old 04-15-2009, 09:30 PM   PM User | #11
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Quote:
Originally Posted by schleppel View Post
You can do it with mod_rewrite
Code:
Options +FollowSymLinks

RewriteEngine On

# If it's not your IP address
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
# Redirect /abc to example.com/abc.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Ok, that's more like what I was looking for.

I'm guessing my IP would go where the "1\.2\.3\.4" is, right?

This wouldn't work with subdomains, though, would it?

Thanks!
BlindSeeker is offline   Reply With Quote
Old 04-15-2009, 10:03 PM   PM User | #12
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
Quote:
I'm guessing my IP would go where the "1\.2\.3\.4" is, right?
Yes.

Quote:
This wouldn't work with subdomains, though, would it?
Do you mean abc.example.com to abc.example.net and def.example.com to def.example.net?
Code:
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
# Match the sub domain (if there is one).
RewriteCond %{HTTP_HOST} ^(.+\.)?example\.com$ [NC]
# %1 is the sub domain (or empty).
RewriteRule ^(.*)$ http://%1example.net/$1 [R=301,L]
schleppel is offline   Reply With Quote
Old 04-15-2009, 10:46 PM   PM User | #13
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Yes, that's what I meant.

For some reason, the code isn't working for me. I put in my IP address, keeping the code exactly like you had it, and put it in the htaccess file, but I still get redirected to tutwow.com. Any thoughts?
BlindSeeker is offline   Reply With Quote
Old 04-15-2009, 10:59 PM   PM User | #14
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
I can't see anything wrong with it.

Have you cleared your browser's cache?

If you use
Code:
Options +FollowSymLinks

RewriteEngine On

RewriteRule test http://example.com/?ip=%{REMOTE_ADDR}&host=%{HTTP_HOST} [R,L]
and go to /test do you get the expected value of ip= and host=?
schleppel is offline   Reply With Quote
Old 04-15-2009, 11:29 PM   PM User | #15
BlindSeeker
New to the CF scene

 
Join Date: Apr 2009
Location: United States
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
BlindSeeker is an unknown quantity at this point
Ok, that was my problem. When I did an "ifconfig" on my mac, it must have given me a wrong IP address for some reason. I changed the IP in the code, and it works perfectly now.

Thanks so much for helping!
BlindSeeker is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:21 AM.


Advertisement
Log in to turn off these ads.