我的CakePHP 2网站上有以下.htaccess文件 我把它放在webroot文件夹下。
每天都有一些机器人尝试以wordpress网站的身份登录我的网站。所以我需要限制一些文件名(wp-login.php)或某些目录,如Administrator或Cache。
如何限制该文件和文件夹?
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order allow,Deny
Deny from all
</FilesMatch>
<Files wp-login.php>
Order allow,deny
Deny from all
</Files>
#<Directory /Administrator>
# Order allow,deny
# Deny from all
#<Directory>
#<Directory /Cache>
# Order allow,deny
# Deny from all
#<Directory>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
#set file cache maximum age in seconds
<ifmodule mod_headers.c>
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=518400, public"
</filesmatch>
<filesmatch "\.(js|css)$">
Header set Cache-Control "max-age=604800, public"
</filesmatch>
</ifmodule>
# gzip files
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# gzip files
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
编辑:我将重定向代码更改为此。目录问题已解决,但CakePHP样式Interval服务器错误异常仍然存在。
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order allow,Deny
Deny from all
</FilesMatch>
<Files "wp-login.php">
Order allow,deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^/?(administrator|cache|undefined) - [L,F,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
答案 0 :(得分:3)
您不能在htaccess文件中使用<Directory>
块。我不确定为什么你的wp-login.php会出现500错误,但你需要在声明中添加一些引号:
<Files "wp-login.php">
Order allow,deny
Deny from all
</Files>
您可以将单个htaccess文件放在仅仅的Administrator
和Cache
目录中:
Order allow,deny
Deny from all
或者您可以使用类似重写规则的内容:
RewriteRule ^/?(Administrator|Cache) - [L,F]