当前位置: 首页 > 网络学院 > 设计教程 > 设计理念 > 利用.htaccess控制网站

设计理念
Flash网页设计的优点与缺点
大学网站内容应该从简
设计适合所有浏览器的网站
高水平网站设计的三个主要规则
根据你的需要选择网站类型
网站内容翻译
文化影响网站本地化
改进网站的几条建议
创建吸引用户的确认网页
优化网站图片
设计小型网站的7条重要规则
运用免费工具检查链接系统
避免使用Splash引导页
数码摄影中避免出现高压缩率的图片
避免出现网站设计错误
网站外观设计也很重要
网站设计应该从简
合理安排网站文字内容
设计站点定义
网站内容比布局更重要

设计理念 中的 利用.htaccess控制网站


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1859 ::
收藏到网摘: n/a

Gain_More_Web_Site_Control_With_htaccessThere are many tools of the trade in the world of Web site development, but very few have as many good uses as your .htaccess file. What, you don't have one? I'll admit, information on these little darlings are confusing to some and hard to find. Hence the reason why we need an explanation of what it is and what it can do for you.

网站开发工具很多,.htaccess文件是很好用的一种,你是否想拥有呢?我知道,有些人难以理解这个内容,并且很难找到关于这个问题的说明,所以这篇文章将会解释.htaccess 文件是什么,以及它有什么作用。

Inside your Web hosting space, you know you have folders, HTML documents, and other things that make your Web site work. Think of this file as just another addition to the many thing you have inside there. It usually sits inside your root directory, such as "/public_html/" and has more than a few good uses. You might already have a .htaccess file in your root directory. If so, all you need to do is edit that one. Just remember that if it is in your root directory, that it will effect all folders and documents inside that directory. If you want to over ride that, then you will have to make a new .htaccess file inside the directory in question.

在网站虚拟主机空间中,存在文件夹、HTML文件以及其它保证网站运行的内容。你可以把这个文件想象成虚拟主机内部其它文件的另一个附加品,通常位于根目录中(比如"/public_html/"),用途有很多。假如根目录中已经存在一个.htaccess文件,你需要进行编辑。但请记住:如果文件存在于根目录中,修改根目录会影响根目录中的所有文件夹以及文件。如果希望在不影响其它内容的情况下修改,你需要在根目录中建立一个新的.htaccess文件。

For an example, if you want what is in the .htaccess file to effect everything but your "photos" folder then you would have to create a new .htaccess file inside your "photos" folder.

比如说,你希望.htaccess文件影响除去照片外的其它内容,你就需要在“照片”文件夹中建立新的.htaccess文件。

How can you create one? Well, depending on the FTP program you are using it should be as easy as creating a new document, then renaming it .htaccess. Note that it has nothing coming before the dot. If you have anything in front of the dot, then it will not be read by the Web hosting server as a .htaccess file. The server will not know what to do with it.

如何创建.htaccess文件呢?你可以利用FTP程序,很容易创建出新文件,然后重命名.htaccess。请注意:文件名中点的前面不能出现任何内容,否则虚拟主机服务器不会把其看作是.htaccess文件,服务器也就不知道如何处理这个文件。

If you want to create the file on your computer first, you should be able to right-click your desktop and select "New" then "Text Document". Then right-click that document on your desktop, and go to "Rename". Type in the new name as ".htaccess". Some programs might put the .txt extension on it automatically. All you have to do is go in to rename it again, and take that part off.

如果你希望首先在计算机中创建这个文件,你应该首先进入桌面,选择“新建”,然后点击“文本文档”,点击桌面上的文件,选择重命名,键入".htaccess",有些程序可能会自动留下扩展名.txt,你需要重新命名文件,然后去掉此部分内容。

Another thing to remember is if you are creating the file on your own computer or uploading it from your own computer, make sure you are uploading it in ASCII mode, not binary. Most FTP programs do a pretty good job at auto-detecting how it should be uploaded, but if you run into a problem that is the first place I would check.

你需要注意的另外一点是,在电脑中创建文件以后,确保利用ASC II模式(非二进位的)上传。大多数FTP程序会自动监测上传情况,但如果出现问题,我会首先检查这个程序。

Also, .htaccess files can only be created on a Linux based server running Apache. If you are not sure if you fall into that category login to your control panel your Web host provided you and snoop around in there. If you are still not sure, feel free to ask your Web host. That is what they are there for! You may need to CHMOD the htaccess file to 644 so the sever can execute the commands inside it.

.htaccess
文件只能在支持Linux的服务器中创建。如果不确定是否属于此种类型,你可以登录控制面板,检查一下;如果还不确定,询问虚拟主机供应商。你可能需要定义htaccess文件为CHMOD644,这样服务器可以执行文件中的指令。

Now you know how to create an empty .htaccess file. Now it is time to start filling it up with some easy to learn and useful commands. Think of each line you put into the .htaccess file as a command for the Web hosting server to do something. Here is an example of what I mean. Think of this as the content of your .htaccess file:

现在你可能了解了如何创建空的.htaccess文件,下面应该在文件中添加一些容易学习、使用的指令。.htaccess文件中的每一条指令,虚拟主机服务器都必须遵循。你的文件内容可以如下:

  • Take out the trash(排除无意义内容)
  • Clean the sink(清空内容)
  • Mow the yard(清扫)
  • Rake the leaves(最后清理)


Each are short commands you might do during your own day. A .htaccess file is much like giving the Web hosting server a to do list. Most commands in the .htaccess file are suppose to be on one line only. This is just the way that the server reads the information.

每一条指令都可能是你需要做的内容。一个.htaccess文件相当于为虚拟主机服务器提供一张列表,文件中的大多数指令应该出现在一行中,服务器就是这样阅读信息。

Another warning you might take in consideration is the ability to use the .htaccess file at all. Some Web hosts have banned it or banned it for certain uses because it causes stress and strain on the Web hosting server itself. Make sure you read through your Web host's frequently asked questions and acceptable use policy before moving forward. If they have something against it, then it should be in one of those two places.

你需要考虑的另外一个问题就是,服务器是否可以利用.htaccess文件。有些虚拟主机不支持这个文件,或者不支持这个文件的某项作用,因为这样会引起虚拟主机服务器的运行压力。利用文件之前,首先阅读虚拟主机使用条件以及各种常见问题,避免浪费时间。

Now that you have it, what can you do with it? That is another few articles all together. Some of the coolest things are password protection, error page redirects, and deny/allow IP address to access your Web site.

现在如何利用这个文件呢?我们会在以后的文章中介绍。我们还会介绍到密码保护、出错页面设计以及IP地址问题等等。

评论 (0) All

登陆 | 还没注册?