Forum Moderators: phranque
here is the leech protection script I got from my host provider.
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!yourdomainname [NC]
RewriteRule .*\.(gif¦jpeg¦jpg¦png)$ - [F] how do I add my redirct to this file like this?
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!yourdomainname [NC]
RewriteRule .*\.(gif¦jpeg¦jpg¦png)$ - [F]
RewriteRule ^old.html$ /new.html [R]
or like this?
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!yourdomainname [NC]
RewriteRule .*\.(gif¦jpeg¦jpg¦png)$ - [F]
RewriteEngine On
RewriteRule ^old.html$ /new.html [R]
or like this?
RewriteEngine On
RewriteRule ^old.html$ /new.html [R]
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!yourdomainname [NC]
RewriteRule .*\.(gif¦jpeg¦jpg¦png)$ - [F]
also I suppose I just load this htaccess file into the root directory right?
Since the rules are mutually exclusive based on filetype, their order doesn't matter.
Only one RewriteEngine on directive is needed.
The code can be cleaned up a bit, and contains several errors.
RewriteEngine On
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !yourdomain\.com [NC]
RewriteRule \.(gif¦jpeg¦jpg¦png)$ - [F]
#
RewriteRule ^old\.html$ http://yourdomain.com/new.html [R=301,L]
Use a 301 redirect and a canonical URL -- rather than the default 302 and a local path -- if the pages have been renamed permanently. Failure to do so may cause unpleasant results in your search engine listings.
Use the [L] flag to stop mod_rewrite processing and redirect immediately when a rule matches. Using this flag can significantly speed up processing of long lists of rules if they are ordered in most-likely-to-match-first order. Use the [L] flag unless you actually want to process the output of a given rule through all subsequent rules.
You may also need to add
Options +FollowSymLinks
at the top of this code in order to get it to work on your server. Whether you need to do this depends on how your host has configured the server. .htaccess files can go into any Web-accessible directory on your site. In this case, put the .htaccess file into the same directory as your "home page."
Posting on this forum modifies some charactrers. Change the broken pipe "¦" characters back to solid pipes before trying to use code posted here.
A bit of friendly advice: Test your simplest rule first. Then add a few more. Don't try uploading a huge file of untested rules onto a server you've never tested mod_rewrite on before. This way lies madness. If you do have trouble, the first place to look is in your server error log file -- It will often tell you specifically what is wrong.
When testing access-control code like this, flush your browser cache (Temporary Internet Files) before testing any change to the code. Otherwise, the cached copies of requested resources will cause invalid test results (Your rules can only affect resources fetched from your server. If the resources are cached locally, the browser will use the cached copies, and they won't be fetched from the server, and your rules will have no effect).
Our forum charter [webmasterworld.com] includes links to several mod_rewrite-related resources.
Jim
Order Deny,Allow
Deny from www.loser.com
Allow from all
#
RewriteEngine On
RewriteRule ^old\.html$ http://mydomain.com/new.html [R=301,L]
The image leetch protection I have working in my other directory because there are some images in my root that I want accessed.
Ive been studying I'm just having trouble findind info about adding different types of directives to the same file. is this how it's done?
edited because of error I noticed.
[edited by: Reid at 12:22 am (utc) on Mar. 11, 2005]
Order [b]Allow,Deny[/b]
Deny from www.loser.com
Allow from all
#
RewriteEngine On
RewriteRule ^old\.html$ http://mydomain.com/new.html [R=301,L]
Jim
One thing I am scrattching my head over Jim is that I found out it is a good idea to put a 301 redirect to make your URL cannonical in order to prevent google from spidering yur site twice and penalizing you for duplicate content.
I've tried every possible combination to do this but when I use an online server header checker I always get the same results.
When I test mysite.com it responds 302 found
When I test www(dot)mysite.com it reponds 200 ok
This is what I am using :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ ht(ignore)tp://www.mysite.com/$1 [R=permanent,L] I tried adding
Options +FollowSymLinks
above it but that causes 500 internal server error. I'm wondering if it is because my virtual host is already doing a 302 upstream or what?
If they are this could be a problem?
Summary of host's e-mail response:
Your domain is hosted on a shared-hosting server. Some mod-rewrite rules take precedence over your own. Long before the rules in your .htaccess file ever gets processed, the server-wide URL rewrites have already taken effect.Unfortunately, these server-wide settings force a 302 Temporarily Moved response header, instead of the desired 301. While it may seem like a minor change on our part to change the default method of redirection, this is not something that we can do easily because of the server management software that we use and the scripts that depend on the 302 header. I will notify the administrators about this issue, though.
I have a friend who uses a different 'shared hosting server' and his does not use a 302 redirect so they got 2 months (before renewal) to fix it - or at least make me feel better. I haven't had a problem so far - I think they are blocking robots on the other side but what if someone links to me without the www? that would be a 302 to me.
[edited by: jdMorgan at 5:15 pm (utc) on Mar. 27, 2005]
[edit reason] Summarized e-mail response. See TOS. [/edit]