Web Hosting Talk







View Full Version : .htaccess Redirect


neojames
09-28-2009, 03:56 PM
I would like to have visitors from a specific hostname redirected to a certain .php page. I would prefer to do this from the .htaccess file as I don't want to muck about to much with the code of my joomla installation (beside the plugin, module and theme ui's).

Thank you for your help,
neojames:D.

mattle
09-28-2009, 04:44 PM
http://tinyurl.com/ycdyd9f

Just remember, REMOTE_HOST AND REMOTE_ADDR are easily spoofed.

neojames
09-29-2009, 11:30 AM
Thank you very much for the help!

neojames
09-29-2009, 12:02 PM
I'm afraid it dosnt quite do what I want, I'm trying to setup a page which will come up if they are on the list. Basicly this will just say that they have been blocked. I would prefer to use hostnames at the moment (as I already have a list of hostnames to use). Thank you for your help!

cartikadave
09-29-2009, 01:13 PM
Are you speaking of blocking them via a 403 access denied. And send all 403/access denied to a custom page?

Are these to be blocked via HTTP_REFERER, REMOTE_HOST, HTTP_USER_AGENT, or IP address?

cartikadave
09-29-2009, 01:23 PM
I posted the following below that would go in your .htaccess with a few examples.

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^38\.118\.42\.* [OR]
RewriteCond %{HTTP_REFERER} example\.com [OR]
RewriteCond %{HTTP_REFERER} spyfu\.com [OR]
RewriteCond %{HTTP_USER_AGENT} "dejan" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "discobot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "zermelo" [NC]
RewriteRule ^.*$ http://www.yourwebsite.com/your-error-page.php [L,R]

neojames
09-29-2009, 04:25 PM
Thank you, but could you please explain it so I know how to mod it later, I'm a bit new to using the .htaccess.

daz07
09-29-2009, 10:08 PM
Thank you, but could you please explain it so I know how to mod it later, I'm a bit new to using the .htaccess.

Well, just look for some keywords.


RewriteEngine On #This line is required to tell apache to turn on mod_rewrite support

# REMOTE_ADDR is the IP of the person. Hostnames should resolve to IPs,
# but personally I'd probably block IPs.
# All lines below specify who is blocked
RewriteCond %{REMOTE_ADDR} ^38\.118\.42\.* [OR] # This will block the IP range 38.118.42.0 through 38.118.42.255 (as denoted by the *)
RewriteCond %{HTTP_REFERER} example\.com [OR] # Blocking a referer; who sent the user to the page
RewriteCond %{HTTP_REFERER} spyfu\.com [OR] # Another of the above
RewriteCond %{HTTP_USER_AGENT} "dejan" [NC,OR] # the user agent is a string browsers send to identify who they are (Ex: Mozilla/IE/Chrome/Safari/Opera will have a longish string with version info inside too
RewriteCond %{HTTP_USER_AGENT} "discobot" [NC,OR] #So this, the line above and below are blocking specific user agents, in this case they are bots (spiders) (as most bots identify themselves with a unique user agent)
RewriteCond %{HTTP_USER_AGENT} "zermelo" [NC] # Again with all of the above..
RewriteRule ^.*$ http://www.yourwebsite.com/your-error-page.php [L,R] # ALl right! So if any of the above "RewriteCond"itions are met, the rule is to redirect all traffic "^.*$" to yourwebsite.com/errorpage by redirection "[L,R]"


Not the best with htaccess either, but that should give you the gist.

.. and before you ask I figure I should throw out there that "#" is the comment symbol used in htaccess. Anything after it will not be executed which is how you can place plain text in the file..

neojames
09-30-2009, 03:01 PM
Thank you, i've been meaning to to that for a while! Thank You!

hostedweb
10-09-2009, 09:18 AM
Just what i needed, thanks!