apache2.4.33伪静态配置入门教程(1)
伪静态: 把动态网页的请求方式伪装成静态网页
要使用伪静态技术,要在httpd.conf中启用伪静态模块:
- LoadModule rewrite_module modules/mod_rewrite.so
把前面的#号去掉
通常利用Apache的rewrite模块对 URL 进行重写的时候, rewrite规则会写在 .htaccess 文件里。但要使 apache 能够正常的读取.htaccess 文件的内容,就必须对.htaccess 所在目录进行配置。从安全性考虑,根目录的AllowOverride属性一般都配置成不允许任何Override ,即
- <Directory />
- AllowOverride None
- Require all denied
- </Directory>
一、在 AllowOverride 设置为 None 时, .htaccess 文件将被完全忽略, 当此指令设置为 All 时,apache才会读取.htaccess中的规则并应用
我的DocumentRoot:
- DocumentRoot "/www"
- root@dev:/www# ls -a
- . .. .htaccess index.htm
- root@dev:/www# cat .htaccess
- RewriteEngine on
- RewriteRule ^(.*)\.html$ $.htm
- root@dev:/www# cat index.htm
- <h3>this is index.htm</h3>
- root@dev:/www#
.htaccess规则详解:
RewriteEngine on #开启伪静态
RewriteRule ^(.*)\.html$ $1.htm #当访问以.html结尾的文件时,会被路由到(.*).htm的地址,比如:
访问http://localhost/index.html -----> 会被规则解释为http://localhost/index.htm,这样读到的内容是www目录下的index.htm文件的内容
要使伪静态生效,需要对/www 目录设置为
- Options Indexes FollowSymLinks
AllowOverride All- Require all granted
我的httpd.conf配置:
1,去除httpd.conf中的注释和空行
- grep -v "^\s*#" httpd.conf | grep -v "^$" > httpd.conf.bak
2,httpd.conf完整配置:
- ServerRoot "/usr/local/httpd24"
- Listen
- LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
- LoadModule authn_file_module modules/mod_authn_file.so
- LoadModule authn_core_module modules/mod_authn_core.so
- LoadModule authz_host_module modules/mod_authz_host.so
- LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
- LoadModule authz_user_module modules/mod_authz_user.so
- LoadModule authz_core_module modules/mod_authz_core.so
- LoadModule access_compat_module modules/mod_access_compat.so
- LoadModule auth_basic_module modules/mod_auth_basic.so
- LoadModule reqtimeout_module modules/mod_reqtimeout.so
- LoadModule filter_module modules/mod_filter.so
- LoadModule mime_module modules/mod_mime.so
- LoadModule log_config_module modules/mod_log_config.so
- LoadModule env_module modules/mod_env.so
- LoadModule headers_module modules/mod_headers.so
- LoadModule setenvif_module modules/mod_setenvif.so
- LoadModule version_module modules/mod_version.so
- LoadModule unixd_module modules/mod_unixd.so
- LoadModule status_module modules/mod_status.so
- LoadModule autoindex_module modules/mod_autoindex.so
- <IfModule !mpm_prefork_module>
- </IfModule>
- <IfModule mpm_prefork_module>
- </IfModule>
- LoadModule dir_module modules/mod_dir.so
- LoadModule alias_module modules/mod_alias.so
- LoadModule rewrite_module modules/mod_rewrite.so
- <IfModule unixd_module>
- User daemon
- Group daemon
- </IfModule>
- ServerAdmin you@example.com
- ServerName 127.0.0.1
- <Directory />
- AllowOverride None
- Require all denied
- </Directory>
- DocumentRoot "/www"
- <Directory "/www">
- Options Indexes FollowSymLinks
- AllowOverride All
- Require all granted
- </Directory>
- <IfModule dir_module>
- DirectoryIndex index.html
- </IfModule>
- <Files ".ht*">
- Require all denied
- </Files>
- ErrorLog "logs/error_log"
- LogLevel warn
- <IfModule log_config_module>
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
- LogFormat "%h %l %u %t \"%r\" %>s %b" common
- <IfModule logio_module>
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
- </IfModule>
- CustomLog "logs/access_log" common
- </IfModule>
- <IfModule alias_module>
- ScriptAlias /cgi-bin/ "/usr/local/httpd24/cgi-bin/"
- </IfModule>
- <IfModule cgid_module>
- </IfModule>
- <Directory "/usr/local/httpd24/cgi-bin">
- AllowOverride None
- Options None
- Require all granted
- </Directory>
- <IfModule headers_module>
- RequestHeader unset Proxy early
- </IfModule>
- <IfModule mime_module>
- TypesConfig /etc/httpd24/mime.types
- AddType application/x-compress .Z
- AddType application/x-gzip .gz .tgz
- </IfModule>
- <IfModule proxy_html_module>
- Include /etc/httpd24/extra/proxy-html.conf
- </IfModule>
- <IfModule ssl_module>
- SSLRandomSeed startup builtin
- SSLRandomSeed connect builtin
- </IfModule>
对于伪静态,主要注意伪静态模块是否加载,Directory下面的设置
二,也可以把伪静态规则写在apache配置文件的Directory段,为了验证配置的作用,可以先把.htaccess删除或者重命名
- root@dev:/www# ls -a
- . .. .htaccess.bak index.htm
- <Directory "/www">
- Options Indexes FollowSymLinks
- AllowOverride none
- RewriteEngine on
- RewriteRule ^(.*)\.html$ $.htm
- Require all granted
- </Directory>
即使AllowOverride 设置为none,伪静态依然生效,注意修改完apache的配置文件需要重启apache服务器
- /usr/local/httpd24/bin/apachectl restart
apache2.4.33伪静态配置入门教程(1)的更多相关文章
- fis3前端工程构建配置入门教程
一.前言 fis3是百度推出的一款前端工程构建工具,类似的还有webpack,gulp等工具:无论大家有没有使用过,从事前端行业应该都略知一二了,所以对于此类工具用干嘛的我这里就不做重复了. 其实对于 ...
- spring security 3.x 多页面登录配置入门教程
最近在最shiro的多入口登录,搞了好久,就把spring security拿出来再炒一下,这是我以前在csdn写过的一篇博客. spring security 是一个权限控制的框架.可以很方便地实现 ...
- nginx伪静态配置教程总结
在nginx中配置伪静态,也就是常说的url重写功能,只需在nginx.conf配置文件中写入重写规则即可. 当然,这个规则是需要熟悉正则表达式,只掌握nginx自身的正则匹配模式即可,对正则不了解的 ...
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0 +VS 2013 开发环境配置
图片太多,具体过程参照: [OpenCV入门教程之一] 安装OpenCV:OpenCV 3.0.OpenCV 2.4.8.OpenCV 2.4.9 +VS 开发环境配置 说下我这边的设置: 选择deb ...
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/19809337 作者:毛星云(浅墨 ...
- DZ 3.2 URL 伪静态配置 教程
原文转自:http://www.zccode.com/thread-682-1-1.html 教程说明: 1 首先需要下载URL重写工具,拷到服务器下面安装即可,这里配置IIS7(x64)伪静态. 工 ...
- PyCharm 2017 官网 下载 安装 设置 配置 (主题 字体 字号) 使用 入门 教程
一.安装 Python 3.6 首先,要安装好 Python 3.6.如果你还没有安装,可以参考咪博士之前的教程 Python 3.6.3 官网 下载 安装 测试 入门教程 (windows) 二.官 ...
- Spring Cloud 入门教程 - 搭建配置中心服务
简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...
- Spring Cloud 入门教程(三): 配置自动刷新
之前讲的配置管理, 只有在应用启动时会读取到GIT的内容, 之后只要应用不重启,GIT中文件的修改,应用无法感知, 即使重启Config Server也不行. 比如上一单元(Spring Cloud ...
随机推荐
- Linux Shell脚本编程提高(12)
实际上Shell是一个命令解释器,它解释由用户输入的命令并且把它们送到内核,不仅如此,Shell有自己的编程语言用于对命令的编辑,它允许用户编写由shell命令组成的程序.Shel编程语言具有普通编程 ...
- 模拟ssh、黏包、hashlib模块
一.模拟ssh 1.subprocess模块 ipconfig -all dir subprocess模块是python从2.4版本开始引入的模块.主要用来取代 一些旧的模块方法,如os.system ...
- 简单线性回归问题的优化(SGD)R语言
本编博客继续分享简单的机器学习的R语言实现. 今天是关于简单的线性回归方程问题的优化问题 常用方法,我们会考虑随机梯度递降,好处是,我们不需要遍历数据集中的所有元素,这样可以大幅度的减少运算量. 具体 ...
- underscore.js源码研究(5)
概述 很早就想研究underscore源码了,虽然underscore.js这个库有些过时了,但是我还是想学习一下库的架构,函数式编程以及常用方法的编写这些方面的内容,又恰好没什么其它要研究的了,所以 ...
- python 跨平台获取网卡信息和本机ip地址
笔者在项目中遇到过获取本机网卡ip的例子,利用python库psutil解决了此问题. def get_netcard(): """获取网卡名称和ip地址 "& ...
- POJ 2726
#include <iostream> #include <algorithm> #define MAXN 10005 using namespace std; struct ...
- Oracle EXPDP/IMPDP示例
待整理: 参考DAVE博客 http://blog.csdn.net/tianlesoftware/article/details/6260138
- winform计算文本的所占的像素长度
/// <summary> /// 计算文本的宽度 /// </summary> /// <param name="str"></para ...
- 如何在Ubuntu 14.04上利用jexus搭建支持php+mysql数据库的网站服务
准备部分:sudo apt-get update sudo apt-get install unzip -y第一部分:安装jexus 在终端运行以下命令 cd /tm ...
- qtcreator_process_stub中文输出乱码
使用qt运行程序输出中文,全都变成了□,让人很头疼,百度了很久,找了一些解决方案都是: 用vim打开x11-common,在控制台输入 vim /etc/X11/Xresources/x11-comm ...