Rootop 服务器运维与web架构

apache 开启 .htaccess

| 暂无评论

       修改httpd.conf配置文件,开启加载mod_rewrite.so 模块

LoadModule rewrite_module modules/mod_rewrite.so

    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#

# AllowOverride None

    AllowOverride All

将.htaccess文件放置于网站根目录即可。重启apache服务生效。

参考文档:https://www.rootop.org/ApacheManual/Apache2.2_zh_CN/howto/htaccess.html

常见配置语法:

 在linux下,可以手动创建一个.htaccess文件   //touch .htaccess

自定义错误页
       .htaccess的一个应用是自定义错误页面,这将使你可以拥有自己的、个性化的错误页面

可以通过在.htaccess文件里加入下面的文字将其变成自定义页面:
ErrorDocument {ErrorNumber} /file.html
比如根目录下有一个notfound.html文件,我想使用它作为404 error的页面:
ErrorDocument 404 /notfound.html
如果文件不在网站的根目录下,你只需要把路径设置为:
ErrorDocument 404 /errorpages/404.html
以下是一些最常用的错误:
401 – Authorization Required 需要验证
400 – Bad request 错误请求
403 – Forbidden 禁止
500 – Internal Server Error 内部服务器错误
404 – Wrong page 找不到页面

如果想更加具体的了解.htaccess的使用,那可以参照Appache的doc中相关的文档及其它网站资料。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/401.html

作者:Venus

服务器运维与性能优化

发表回复