.htaccess 阻止某些内部页面上的图像
我正在为一位朋友做一些网页设计,我注意到除了我正在工作的子目录之外,她网站上的其他所有图像都可以正常加载。我查看了她的 .htaccess 文件,果然它被设置为拒绝人们访问盗用她的照片。很公平,除了我正在处理的页面在她的域中,但我仍然收到 403 错误。我在下面粘贴 .htaccess 内容,但我将域名替换为 xyz、123 和 abc。
因此,具体来说,我所在的页面 (xyz.com/DesignGallery.asp) 从 (xyz.com/machform/data/form_1/files) 提取图像,并导致出现禁止错误。
RewriteEngine on
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTP_REFERER} !^http://xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
deny from 69.49.149.17
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.html$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.asp$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.asp$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.html$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.html$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.asp$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.html$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.asp$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
I'm doing some web design for a friend and I noticed that everywhere else on her site images will load fine except for the subdirectory I'm working in. I looked in her .htaccess file and sure enough it is setup to deny people from stealing her images. Fair Enough, except the pages i'm working on are in her domain and yet I still get the 403 error. I'm pasting the .htaccess contents below but I replaced the domain names with xyz, 123 and abc.
So specifically the page I'm on (xyz.com/DesignGallery.asp) pulls images from (xyz.com/machform/data/form_1/files) and it results in a forbidden error.
RewriteEngine on
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTP_REFERER} !^http://xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://123.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com/machform/data/form_1/files/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.abc.xyz.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.123.xyz.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
deny from 69.49.149.17
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.html$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ArtGraphics\.asp$ "http\:\/\/www\.xyz\.com\/Art_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.asp$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Gear\.html$ "http\:\/\/www\.xyz\.com\/Gear_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.html$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^NewsletterSign\-Up\.asp$ "http\:\/\/www\.xyz\.com\/Newsletter\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.html$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^KidzStuff\.asp$ "http\:\/\/www\.xyz\.com\/KidzStuff1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.html$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Vendors\.asp$ "http\:\/\/www\.xyz\.com\/Design_Gallery_1\.htm" [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我敢打赌,其中一个指令中存在语法错误,您在替换 www.xyz.com 时可能已更正该错误。
如果您有权访问 httpd.conf,则可以设置
RewriteLog
和RewriteLogLevel
指令来了解尝试加载图像时发生的情况。您应该能够很容易地识别出有问题的线路。 (完成后请务必删除这些指令。)如果您无法访问 httpd.conf,则可以逐一删除这些行,直到找到违规者。
(一旦完成这一切,您可能可以大大简化
.htaccess
文件。大多数重写条件都是多余的。很容易出现微小的错误而不被注意到)I'll bet its a syntax error in one of the directives, that you may have corrected when substituting www.xyz.com.
If you have access to httpd.conf, you could set up the
RewriteLog
andRewriteLogLevel
directives to get a sense of what's going on when you try to load the images. You should be able to identify the offending line pretty easily. (Be sure to remove those directives once you're done.)If you don't have access to httpd.conf, you can eliminate the lines one by one until you find the offender.
(Once that's all done, you could probably simplify that
.htaccess
file quite a bit. Most of those rewrite conditions are redundant. Easy for tiny errors to sneak in and not get noticed)