伪静态: 把动态网页的请求方式伪装成静态网页
要使用伪静态技术,要在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 时,所有具有 ".htaccess" 作用域的指令都允许出现在 .htaccess 文件中
我的DocumentRoot:
DocumentRoot "/www"
root@dev:/www# ls -a. ?.. ?.htaccess ?index.htmroot@dev:/www# cat .htaccess RewriteEngine onRewriteRule ^(.*)\.html$ $1.htmroot@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 AllRequire 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 80LoadModule mpm_prefork_module modules/mod_mpm_prefork.soLoadModule authn_file_module modules/mod_authn_file.soLoadModule authn_core_module modules/mod_authn_core.soLoadModule authz_host_module modules/mod_authz_host.soLoadModule authz_groupfile_module modules/mod_authz_groupfile.soLoadModule authz_user_module modules/mod_authz_user.soLoadModule authz_core_module modules/mod_authz_core.soLoadModule access_compat_module modules/mod_access_compat.soLoadModule auth_basic_module modules/mod_auth_basic.soLoadModule reqtimeout_module modules/mod_reqtimeout.soLoadModule filter_module modules/mod_filter.soLoadModule mime_module modules/mod_mime.soLoadModule log_config_module modules/mod_log_config.soLoadModule env_module modules/mod_env.soLoadModule headers_module modules/mod_headers.soLoadModule setenvif_module modules/mod_setenvif.soLoadModule version_module modules/mod_version.soLoadModule unixd_module modules/mod_unixd.soLoadModule status_module modules/mod_status.soLoadModule autoindex_module modules/mod_autoindex.so<IfModule !mpm_prefork_module></IfModule><IfModule mpm_prefork_module></IfModule>LoadModule dir_module modules/mod_dir.soLoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.so<IfModule unixd_module>User daemonGroup daemon</IfModule>ServerAdmin you@example.comServerName 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 builtinSSLRandomSeed connect builtin</IfModule>
对于伪静态,主要注意伪静态模块是否加载,Directory下面的设置
apache2.4.33伪静态配置入门教程(1)
原文地址:https://www.cnblogs.com/ghostwu/p/9048816.html