0

I have a folder structure on my website as follows:

/bin
/bin/home
/bin/home/home.php
index.php
.htaccess

In my .htaccess I route everything through to index.php, which works when you access the website traditionally. My problem is bots, they access home.php and so it fills my website with error_log files because that file is dependent on functionality from other scripts.

How can I stop the bots accessing anything other than index.php? Of course, I need my website to be able to include or require_once any PHP file on the server it needs.

This is my current Rewrite rule list:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect germany shop links to the new shop format
    RewriteCond %{REQUEST_URI}  ^/shop_germany/proddetail\.php$
    RewriteCond %{QUERY_STRING} ^prod=([0-9]*)$
    RewriteRule ^(.*)$ http://example.com/shop/product/%1? [R=permanent,L]

    # Rediret old shop links to the new shop
    RewriteCond %{REQUEST_URI}  ^/shop_en/proddetail\.php$
    RewriteCond %{QUERY_STRING} ^prod=([0-9]*)$
    RewriteRule ^(.*)$ http://example.com/shop/product/%1? [R=permanent,L]

    # Redirect all queries to SSL port 443
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # Don't allow www.example.com, redirect to https://example.com
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

    # Route everything via index.php
    RewriteBase /
    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
    RewriteRule \.(jpg|jpeg|png|gif|pdf)$ - [NC,F,L]
</IfModule>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chud37
  • 4,907
  • 13
  • 64
  • 116
  • http://stackoverflow.com/questions/18406156/redirect-all-to-index-php-htaccess ? – Leszek P Apr 19 '17 at 07:39
  • @LeszekRepie I've posted my .htaccess because I think its more of a problem in the way its ordered. I tried the example in the link you provided but i could still access /bin/home/home.php – Chud37 Apr 19 '17 at 07:52
  • One option move your bin/ folder to one level up - so it wont be directly accessible, but still can include php scripts - just amend paths. – Leszek P Apr 19 '17 at 08:19
  • Second: http://stackoverflow.com/questions/9282124/deny-direct-access-to-a-folder-and-file-by-htaccess - add htaccess to bin folder to prevent direct accessing files – Leszek P Apr 19 '17 at 08:19

0 Answers0