homepage Welcome to WebmasterWorld Guest from 107.20.34.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Redirect help for .htaccess
.htaccess redirect IP
maxidrom11



 
Msg#: 357 posted 8:43 pm on Dec 28, 2002 (gmt 0)

Sorry for my English - hope you understand what I mean.
Could you please help me compose .htaccess in a right way. I would like to redirect visitors with particular IP to the certain page of my web site. I read an article where it said how to do that but only for one IP address -
I need the same but for a number of IPs with a right sintax.
I also would like to know the proper sintax for sub networks to redirect
all visitors from ditermined country like 000.000.00.*. and so on. Here is an
example I was offered for 192.12.131.1. Please, help me add more IPs with
right sintax. Thank you!

SetEnvIf REMOTE_ADDR 192.12.131.1 REDIR="redir"
RewriteCond %{REDIR} redir
RewriteRule ^/$ /page.html

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 357 posted 3:11 am on Dec 29, 2002 (gmt 0)

maxidrom11,

Welcome to WebmasterWorld [webmasterworld.com]!

Here are some examples for you to try:

SetEnvIf REMOTE_ADDR 192.12.131.1 REDIR="redir"
SetEnvIf REMOTE_ADDR 192.12.131.2 REDIR="redir"
SetEnvIf REMOTE_ADDR 192.12.131.4 REDIR="redir"
SetEnvIf REMOTE_ADDR 192.12.131.7 REDIR="redir"
SetEnvIf REMOTE_ADDR "^192\.12\.132\." REDIR="redir" # redirects 192.12.132.0 - 255
RewriteCond %{REDIR} redir
RewriteRule .* /page.html

You can accomplish the same thing without using SetEnvIf at all. Let RewriteCond test the REMOTE_ADDR environment variable directly:

RewriteCond %{REMOTE_ADDR} ^192\.12\.131\.(1񔘞7)$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.12\.132\.$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.12\.132\.(19[6-9]2[0-4][0-9]25[0-5])$ # 192.12.132.196 - 255. Note no [OR] on last RewriteCond!
RewriteRule .* /page.html

Notice, you must replace the "" character in the code above before use - The WebmasterWorld software changes it. Use the one on your keyboard - usually "SHIFT" + "\"

Jim

maxidrom11



 
Msg#: 357 posted 9:56 am on Dec 29, 2002 (gmt 0)

Thank you for your reply it is very helpful. Now I am interested in a proper sintax if I want to redirect those visitors outside like

[somepage.com...]

And one more question I want to ask - Is there a batabase where I can get lists of IP addresses for particular countries like India, Albania, Russia and so on to redirect visitors from those countries to the page.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 357 posted 6:23 pm on Dec 29, 2002 (gmt 0)

maxidrom11,

Please refer to the following resources; It seems your requirements are expanding, so you should learn this for yourself. Redirection is a very useful tool, and worth a few hours of study:

Introduction to mod_rewrite [webmasterworld.com]
Apache mod_rewrite documentation [httpd.apache.org]
WebmasterWorld Site Search tool [searchengineworld.com]

Redirecting by country/region is tricky, since the association between IP address and countries is loose at best. There are services which keep up with IP assignments and maintain IP-to-country databases which you could import or query for a fee. But there are many practical problems with this, and it may just be easier to allow the user to select what country/language customizations are desired.

Hope this helps,
Jim

maxidrom11



 
Msg#: 357 posted 7:31 pm on Dec 30, 2002 (gmt 0)

Well, I read all mode_rewrite docs but my English is not so expanded as my expanded reqiurements especially for tech terms. Thank you very much for the help

Max

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 357 posted 9:01 pm on Dec 30, 2002 (gmt 0)

Max,

Your english is better than my russian! I checked over at AltaVista, but their page translation does not translate english to russian, so hopefully, this will help.

To redirect to an external site, change the RewriteRule:

RewriteCond %{REMOTE_ADDR} ^192\.12\.131\.(1񔘞7)$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.12\.132\.$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.12\.132\.(19[6-9]2[0-4][0-9]25[0-5])$ # Note no [OR] on last RewriteCond
RewriteRule .* http://somepage.com/cgi-bin/page.cgi [R,L]

Notice, you must replace the "" character in the code above before use - The WebmasterWorld software changes it. Use the one on your keyboard - usually "SHIFT" + "\"

Jim

maxidrom11



 
Msg#: 357 posted 8:09 pm on Jan 2, 2003 (gmt 0)

I am so thankful for your messages jdMorgan! Yuo really helped me alot because I am a fresher to all that .htaccess stuff. Could you please show me practically the way to redirect IP like 217.113.224.0 - 217.113.229.128 - it is still hard for me to understand sintax. I beg you! It's very important to me and you are very expierenced.
Could we swap emails if possible - mine is <snip>
Thank you so much!

[edited by: littleman at 5:13 pm (utc) on Oct. 10, 2003]
[edit reason] snipped email address [/edit]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 357 posted 12:33 am on Jan 3, 2003 (gmt 0)

maxidrom11,

I have sent you a solution to this problem. Please check your stickymail - The link "You have mail" at the top of this screen.

Jim

maxidrom11



 
Msg#: 357 posted 1:38 pm on Jan 4, 2003 (gmt 0)

Hi jdMorgan --
Thank you so much for your answers! I feel very welcomed at the forum. I am ok about your privacy.
I happened to read threads dedicated to banning or redirecting so-called
"bad bots" and my head is about to explode - what if I join some sections
in my .htaccess and compose it like this, will it work ok? I do not want to do a thing before asking you 'cos you have a lot of experience as I see.
Sorry for a long list, I am just anxius to know if the sintax ok and working

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Max"
AuthType Basic

ErrorDocument 401 /digitalvideoresources.html
ErrorDocument 403 /digitalvideoresources.html
ErrorDocument 404 /digitalvideoresources.html
ErrorDocument 500 /digitalvideoresources.html

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:<snip>t@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.*$ /digitalvideoresources.html [R]

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^217\.113\.22[4-8]\. [OR]
RewriteCond %{REMOTE_ADDR} ^217\.113\.229\.([0-9]1-9][0-9]1[01][0-9]12[0-7])$
RewriteRule .* [<snip>.com...] [R=301,L]

[edited by: littleman at 5:12 pm (utc) on Oct. 10, 2003]
[edit reason] removed site & id from code [/edit]

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 357 posted 3:34 pm on Jan 4, 2003 (gmt 0)

maxidrom11,

Looks OK to me, with one exception: You should have only one "RewriteEngine on" directive in the file.

A couple of notes in addition:

Many users must add the directive Options +FollowSymLinks before enabling the rewrite engine. If your rewrites don't work, try that.

You can combine some of your RewriteConds to make processing more efficient, example:
RewriteCond %{HTTP_USER_AGENT} ^(DISCoownload\ Demon) [OR]
(Again, be sure to replace the "" character with the one on your keyboard!)

We try not to do code reviews here on WebmasterWorld - You should test your code, and post it only if it doesn't work. While we are happy to help with problems, obviously, we can't help write code for everyone in the world... :)

Jim

maxidrom11



 
Msg#: 357 posted 9:39 pm on Jan 5, 2003 (gmt 0)

Hi Jim --
Thank you so much for your answers! Me again. Maybe it's already irritating for you but does it look fine after my corrections?

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Max"
AuthType Basic
ErrorDocument 401 /digitalvideoresources.html
ErrorDocument 403 /digitalvideoresources.html
ErrorDocument 404 /digitalvideoresources.html
ErrorDocument 500 /digitalvideoresources.html
RewriteOptions +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]

(........continuing list of user agents.................)

RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.*$ /digitalvideoresources.html [R]
RewriteCond %{REMOTE_ADDR} ^217\.113\.22[4-8]\. [OR]
RewriteCond %{REMOTE_ADDR} ^217\.113\.229\.([0-9]1-9][0-9]1[01][0-9]12[0-7])$
RewriteRule .*http://<snip>.com/cgi-bin/redir.cgi?user=<snip>[R=301,L]

[edited by: littleman at 5:06 pm (utc) on Oct. 10, 2003]
[edit reason] removed site & id from code [/edit]

maxidrom11



 
Msg#: 357 posted 12:32 pm on Jan 7, 2003 (gmt 0)

Today I published my .htaccess and the server gave me 500 error. What is still not correct? Please help!

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Max"
AuthType Basic
ErrorDocument 401 /digitalvideoresources.html
ErrorDocument 403 /digitalvideoresources.html
ErrorDocument 404 /digitalvideoresources.html
ErrorDocument 500 /digitalvideoresources.html
RewriteOptions +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule!^digitalvideoresources\.html$ /digitalvideoresources.html [L]
RewriteCond %{REMOTE_ADDR} ^217\.113\.22[4-8]\. [OR]
RewriteCond %{REMOTE_ADDR} ^217\.113\.229\.([0-9]1-9][0-9]1[01][0-9]12[0-7])$
RewriteRule .* [<snip>.com...] [R=301,L]

[edited by: littleman at 5:02 pm (utc) on Oct. 10, 2003]
[edit reason] removed & id site from code [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved