Apache .htaccess 301重定向

RewriteRule ^/?oldpage\.html$/ /newpage.html [R=301,NC,L]

Apache 维护重定向

Options FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REQUEST_URI} !/marrowtanance.png$

RewriteRule $ /maintenance.html [R=302,L]

Apache apache连接数

ps -ef | grep -c httpd

Apache Apache 2.2性能调优

ExpiresActive On
ExpiresByType image/gif "access plus 1 weeks"
ExpiresByType image/png "access plus 1 weeks"
ExpiresByType image/jpeg "access plus 1 weeks"
ExpiresByType text/css "access plus 1 weeks"
ExpiresByType text/javascript "access plus 1 weeks"
ExpiresByType application/x-javascript "access plus 1 weeks"
FileETag none
# Deflate
SetOutputFilter DEFLATE 
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css ap
plication/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

This config is tested with http://ipotpal.bgurl.org

Apache .htaccess - www - > http:// - http:// - > www - 很棒的网址

Options -Indexes
Options +FollowSymLinks
RewriteBase /
RewriteEngine On


## /id/product-name/ to index.php?id=id
RewriteRule ^([0-9]*)/(.*)$ index.php?id=$1 [L]

## non www to wwww ##
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
RewriteRule (.*) http://www.site.com/$1 [R=301,L]


## www to non www ##
RewriteCond %{HTTP_HOST} !^site\.com$
RewriteRule (.*) http://site.com/$1 [R=301,L]

Apache 为静态文件启用gzip压缩

<IfModule mod_deflate.c>
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

Apache Apache:将除X之外的IP重定向到[URL]

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=302,L]

Apache 强制文件下载“保存为”?提示

AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4

Apache 虚拟主机

<VirtualHost *:80>
  ServerName myapp.example.com
  DocumentRoot "/home/steve/myproject/web"
  DirectoryIndex index.php
  Alias /sf /$sf_symfony_data_dir/web/sf
  <Directory "/$sf_symfony_data_dir/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
  <Directory "/home/steve/myproject/web">
    #Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Apache 使用.htaccess强制下载文件

<Files *.*>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</Files>