我的网站上有一个文件夹结构,如下所示:
/bin
/bin/home
/bin/home/home.php
index.php
.htaccess
在我的.htaccess
我将所有内容路由到index.php
,这在您传统访问网站时有效。我的问题是机器人,他们访问home.php
,因此它用error_log
文件填充我的网站,因为该文件依赖于其他脚本的功能。
如何阻止机器人访问index.php以外的任何内容?当然,我需要我的网站能够在其所需的服务器上include
或require_once
任何PHP文件。
这是我目前的重写规则列表:
<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>