Forum Moderators: phranque

Message Too Old, No Replies

htaccess

Is htaccess the right tool for this job?

         

jons

10:45 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



I have external web forums directing traffic to my site via a bogus link to an anchored <a name> tag. For instance, example.com/#TOC:1001
I'd like to capture that inbound attempt and redirect it to my other web site.
A portion of my apache log shows [bogus.com...] and I have tried writing several iterations of:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?bogus.com/showthread.php?t=64029 [NC]
RewriteRule .* [myothersite.com...] [R,L]

but I just can't seem to make it work after reading for the entire day... Is htaccess even the right tool for this task?

jdMorgan

11:28 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Several possible problems, as described in the comment lines below:

#
# The following line may be required to enable mod_rewrite
Options +FollowSymLinks
RewriteEngine on
#
# Escape all regex tokens if they are to be treated as literals, and removed unneeded parens
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?bogus\.com/showthread\.php\?t=64029 [NC]
# Specify either a 301 or 302 redirect
RewriteRule .* http://www.myothersite.com [R=301,L]

A trailing question mark in regular expressions means that the preceding single character (or parenthesized group of characters) is optional. However, if you want to match the literal question mark used to demarcate the "t=64029" query string, then you must precede it with a backslash. Similarly, an unescaped "." means "any single character" and must also be escaped if you want to match a literal period.

Jim

jons

1:54 am on Jun 9, 2006 (gmt 0)

10+ Year Member



Thank you for helping me get it working!