Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: IP and page-specific redirect? |
|
Author |
|
Doug22
Joined: 02 Jun 2013 Posts: 57 Location: Houston TX
|
Posted: Wed 19 Feb '14 4:41 Post subject: IP and page-specific redirect? |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 19 Feb '14 17:05 Post subject: |
|
|
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
|
Posted: Thu 20 Feb '14 1:07 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 20 Feb '14 18:56 Post subject: |
|
|
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
|
Posted: Thu 20 Feb '14 19:16 Post subject: |
|
|
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: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 24 Feb '14 12:09 Post subject: |
|
|
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
|
Posted: Tue 25 Feb '14 21:47 Post subject: |
|
|
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 |
|
|
|
|
|
|