logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: IP and page-specific redirect?
Author
Doug22



Joined: 02 Jun 2013
Posts: 57
Location: Houston TX

PostPosted: Wed 19 Feb '14 4:41    Post subject: IP and page-specific redirect? Reply with quote

I'm at my wits end. I'm trying to get code to go in a .htaccess file that when a specific IP tries to get a specific page, he/she is redirected to another page.

Different folks use noteably different syntax in what they suggest, which is all similar, and I've tried all of them, but nothing works. Either I'm doing something really dumb, or everyone doesn't try the code they suggest. I have tried many variants of this code below ...

Code:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^12\.345\.678\.90$
RewriteCond %{REQUEST_URI} /requested-page\.html$
RewriteRule .* /redirect-to-this-page.html [R=301,L]


... and nothing works. My webserver gets hosed, and my otherwise working system gives me an error when I try to get a page from it. I am, by the way, using Mac 10.6.8, with Apache 2.2 on both server and client.

What will work??
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Wed 19 Feb '14 17:05    Post subject: Reply with quote

Code:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^12\.345\.678\.90$
RewriteRule ^/requested-page\.html /redirect-to-this-page.html [R,NE,NC]
Back to top
Danll



Joined: 02 Aug 2013
Posts: 49
Location: USA, Houston

PostPosted: Thu 20 Feb '14 1:07    Post subject: Reply with quote

Quote:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^12\.345\.678\.90$
RewriteRule ^/requested-page\.html /redirect-to-this-page.html [R,NE,NC]


Nope. Same trouble. I put that in at the end of my .htaccess file, with a remote address that was not mine, and when I send my browser to the "requested-page", I get

Forbidden
You don't have permission to access requested-page.html on this server.


Which is what usually happens when I have a mistake in my .htaccess file. That file is very intolerant of errors. Not sure if it makes a difference, but my requested page is .htm rather than .html. I tried both in the RewriteRule command.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Thu 20 Feb '14 18:56    Post subject: Reply with quote

a 403 ca mean that the redirect works, but not your permissions.
Back to top
Danll



Joined: 02 Aug 2013
Posts: 49
Location: USA, Houston

PostPosted: Thu 20 Feb '14 19:16    Post subject: Reply with quote

Hmm. Well, before I edit my .htaccess file, I can get "requestedpage.html" with no trouble. After I edit it the .htaccess file, I can't. I haven't changed any permissions. In fact, after I edit it, I am told I don't have permission to access ANY page on my server.

I copy those lines *identically* to my .htaccess file, and even place dummy requestedpage.html and redirect-to-this-page.html files on my site, and my site is unusable.

Something is very wrong.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 24 Feb '14 12:09    Post subject: Reply with quote

that .htaccess is is your apache document root, not in a subfolder?

What is in the access log / error log about this?
Back to top
Doug22



Joined: 02 Jun 2013
Posts: 57
Location: Houston TX

PostPosted: Tue 25 Feb '14 21:47    Post subject: Reply with quote

OK, the answer is

Code:
# permanently redirect specific IP request for single page
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^11\.222\.333\.444$
RewriteRule ^requested-page\.html /served-page.html [R,NC,L]


This verifiably works with Apache 2.2. IP 11.222.333.444 asks for "requested-page.html", and is served "served-page.html". My server system is happy.

Put these commands in the .htaccess file for the directory that the request is being sent to.
Back to top


Reply to topic   Topic: IP and page-specific redirect? View previous topic :: View next topic
Post new topic   Forum Index -> Apache