Forum Moderators: phranque
I have a simple 301 redirection in the .htaccess of most of my sites (see code below).
On ANOTHER site that does not include any 301, I'm also using an anti-scraper routine, banning the IPs that do not "behave well". In .htaccess as well (see code below).
However, I was stuck today when trying to implement the 2 options above at the same time, on one same site, with one single .htaccess file. I thought I could just combine the code of these two routines but it creates a pretty bad error (cannot access any page).
Is there anything special I should add like an if/then condition? I honestly thought I could just combine these 12 lines of code to get the functionality I wanted: 301 redirection to www.example.com + anti-scraper trick. Or should I use a particular order?
It can probably be solved very easily but I've tried so many times that I'm getting lost...
-T
A) 301:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}!^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]
B) anti-scraper:
SetEnvIf Remote_Addr ^23\.128\.115\.16$ getout # Fri May 19 10:44:45
((((note: add'l banned IPs go here and are added by a perl script when bots are detected))))
SetEnvIf Request_URI "^(/403.*\.html¦/robots\.txt)$" allowsome
<Files *>
order deny,allow
deny from env=getout
allow from env=allowsome
</Files>
Reply With Quote
I'd suggest:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule [b](.*)[/b] http://www.example.com/$1 [R=301,L]
The rest looks basically OK, although you might want to check our PERL library for updated versions of that script -- It's invalid to include a comment on the same line as a directive, and this may result in a lot of Warnings and slow down your server. This and a file-locking issue were addressed in later versions posted here.
However, neither of the above points is likely to change your immediate problem...
When you get this site-not-accessible error, what is logged in your server error log and server access log? The error log info will often tell you exactly what's wrong, and would be very helpful posted here.
Jim