官方说明:Provides a rule-based rewriting engine to rewrite requested URLs on the fly
检查是否安装模块:
0 1 2 3 |
[root@hk wordpress]# /usr/local/apache/bin/apachectl -M|grep rewrite [root@hk wordpress]# /usr/local/apache/bin/apachectl -l|grep rewrite [root@hk wordpress]# grep rewrite /usr/local/apache/conf/httpd.conf #LoadModule rewrite_module modules/mod_rewrite.so |
安装mod_rewrite模块:
0 1 2 3 4 5 |
[root@hk wordpress]# cd /byrd/tools/httpd-2.4.9/modules/mappers/ [root@hk mappers]# /usr/local/apache/bin/apxs -c -i -a mod_rewrite.c chmod 755 /byrd/server/httpd-2.4.9/modules/mod_rewrite.so [activating module `rewrite' in /byrd/server/httpd-2.4.9/conf/httpd.conf] [root@hk mappers]# /usr/local/apache/bin/apachectl -M|grep rewrite rewrite_module (shared) |
配置虚拟主机:vim /usr/local/apache/conf/extra/httpd-vhosts.con
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<Directory "/var/www/docs"> Options FollowSymLinks AllowOverride all #Options None Require all granted </Directory> <VirtualHost *:80> ServerAdmin Webmaster@t4x.org DocumentRoot "/var/www/docs/t4x.org" ServerName hk.t4x.org ServerAlias hk.t4x.org ErrorLog "logs/dummy-hk.t4x.org-error_log" CustomLog "logs/dummy-hk.t4x.org-access_log" common ExpiresActive on ExpiresDefault "access plus 12 month" ExpiresByType text/html "access plus 12 month" ExpiresByType image/gif "access plus 363636 month" <ifmodule mod_deflate.c> DeflateCompressionLevel 9 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/plain text/xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/css SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary </ifmodule> </VirtualHost> |
.htaccess配置:(以wordpress)
0 1 2 3 4 5 6 7 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] </IfModule> |
申明:本文由BYRD原创(基于Centos6.4 X64、PHP5.5.11、APACHE2.4.9、MYSQL5.6.16),未经许可禁止转载!
参考:http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
参考:http://note.t4x.org/system/apache-mod-deflate/
参考:http://note.t4x.org/system/apache-mod-expires/ SourceByrd's Weblog-https://note.t4x.org/environment/apache-htaccess-rewrite/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!