您好,欢迎来到12图资源库!分享精神,快乐你我!我们只是素材的搬运工!!
  • 首 页
  • 当前位置:首页 > 网站教程 > PHP教程 >
    .htaceess是什么 .htaceess怎么写 .htaceess怎么配置(2)
    时间:2016-04-10 20:27 来源:12图资源库 作者:12too.com 浏览:收藏 挑错 推荐 打印


      RewriteCond %{HTTP_REFERER} !^$

      RewriteCond %{HTTP_REFERER} !^http://(www\.)?phpx.info/.*$ [NC]

      RewriteRule \.(gif|jpg)$ - [F]

      如果觉得让别人的页面开个天窗不好看,那可以用一张图片来代替:

      RewriteEngine on

      RewriteCond %{HTTP_REFERER} !^$

      RewriteCond %{HTTP_REFERER} !^http://(www\.)?phpx.info/.*$ [NC]

      RewriteRule \.(gif|jpg)$ http://www.mrhong.net替代图片文件名 [R,L]

      (3)

      .htaccess is a very useful way to accomplish things that HTML and CSS can't, however it is very rarely allowed on free-servers. You should check with your system administrator to make sure that .htaccess is allowed/enabled before trying out these tutorials.

      1.error pages: customize your 404 error pages.

      We all know what a 404 "Not Found" error page looks like. This tutorial will show you how to make those error pages anything you desire.

      First you'll need to create your error pages. Just make some normal HTML pages, one for each error type. The error types and their definitions are:

      400: Bad Request. The server doesn't understand the request.

      401: Authentication Failed. The password was not accepted.

      403: Access Forbidden. Access to the area is forbidden.

      404: File Not Found. The requested file could not be found.

      500: Internal Server Error. Usually the result of a misconfigured script.

      Once you've made your error pages, upload them to a directory called error or something of the sort.

      Now the important part. Create a file called htaccess.txt in Notepad. Add these lines to the file:

      ErrorDocument 400 http://phpx.info/error/400.html

      ErrorDocument 401 http://phpx.info/error/401.html

      ErrorDocument 403 http://phpx.info/error/403.html

      ErrorDocument 404 http://phpx.info/error/404.html

      ErrorDocument 500 http://phpx.info/error/500.html

      Change iiwnet.com to the location of your website. Save the file and upload it to your top-most web directory. Once it's there, rename it with your FTP program to .htaccess - complete with the dot starting it out, and with no .txt extension this time.

      If the .htaccess file is in your top-most web directory, then all errors that occur in that directory and all its subdirectories will be referred to the appropriate error page.

      That's it! Try it out by going to a page on your website that you know doesn't exist.

      2.private directories: password protect your private folders.

      Ever wanted a password protected directory? Click here for an example, use kali as your username and green as the password. With .htaccess and .htpasswd you can create as many users and passwords as you need.

      To have one of your own, download this cgi script: password.cgi.

      To use it, unzip the script and upload it to your cgi-bin.

      CHMOD it 755 and run it from your web-browser.

      Instructions will be detailed in the script.

      3.anti-leech: stop people from linking to your image files.

      If you've ever gone through your site logs and found someone hotlinking to your image files, stealing your bandwidth, then you need the following lines in your .htaccess file:

      RewriteEngine on

      RewriteCond %{HTTP_REFERER} !^$

      RewriteCond %{HTTP_REFERER} !^http://phpx.info/.*$ [NC]

      RewriteCond %{HTTP_REFERER} !^http://www.mrhong.net/.*$ [NC]

      RewriteRule .*\.(gif|GIF|jpg|JPG|bmp|BMP)$ - [F]

      Change "iiwnet.com" to your own URL, and upload the .htaccess file to the directory containing your images. Once it is in place, only people coming from "iiwnet.com" will be able to view the images; everyone else will only see a broken image placeholder. If you have an image you'd like to display instead of the placeholder, use the version below.

      RewriteEngine On

      RewriteCond %{HTTP_REFERER} !^$

      RewriteCond %{HTTP_REFERER} !^http://iiwnet.com/ [NC]

      RewriteCond %{HTTP_REFERER} !^http://www.mrhong.net/ [NC]

      RewriteCond %{REQUEST_URI} !^/theif.gif [NC]

      RewriteRule \.(gif|GIF|jpg|JPG)$ [R]

      "theif.gif" is the image you want to load whenever someone attempts to hotlink an image from your server. You only need to add the RewriteCond %{REQUEST_URI} !^/theif.gif [NC] line if the image you want to load is in a directory that the .htaccess file effects. Otherwise you can remove the line, and it will still function.
    (责任编辑:admin)