views:

200

answers:

2

How can I use .htaccess to forward a visitor of a specific IP address to a webpage on my server?

This example causes an infinite loop:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteRule ^(.*)$ /specialpage.php [R,L] 

I found this on the web but it just does not work:

SetEnvIf REMOTE_ADDR 123.123.123.123 REDIR="redir"
RewriteCond %{REDIR} redir
RewriteRule ^(.*)$ /specialpage.php

Note: My website consists of .htm, html and .php pages.

Your help would be very much appreciated.

+1  A: 

Add a condition to not rewrite when you're already at specialpage:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule ^(.*)$ /specialpage.php [R,L] 
Wim
Almost! Unfortunately, the CSS is not loaded anymore now. Any help?
Jim Knopf
+1  A: 

Just figured out the solution:

RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
RewriteCond %{REQUEST_URI} !/specialpage.php
RewriteRule .*\.(htm|html|php)$ /specialpage.php [R,L]

Thank you for your help!

Jim Knopf