Apache 通过htaccess反向代理

# This rule will send the requests that client made as being from our server to the
# server_name specified.
# Combined with a named apache virtualhost this can be used to expose multiple webservers
# behind the same IP public address. The server were we put this config will act as a
# gateway and the public IP address must point to him.

RewriteRule ^(.*)$ http://server_name/$1 [P,L]
RewriteRule ^$ http://server_name/ [P,L]

Apache HTACCESS重定向所有流量

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Apache htaccess片段

### REWRITE DEFAULTS ###
RewriteEngine On
RewriteBase /

## FORCE WWW ##
RewriteCond %{HTTP_HOST} ^url\.com$ [NC]
RewriteRule ^(.*)$ http://www.url.com/$1 [L,R=301]

## REMOVE index.php ##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Apache 重定向到www。域无需硬编码域

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	# redirect non-www to www
	RewriteCond %{HTTP_HOST} ^([a-z-]+)\.([a-z]{2,6})$ [NC]
	RewriteRule ^(.*)$ http://www.%1\.%2/$1 [R=301,L]
</IfModule>

Apache Htaccess速度提升

# Start Gzip
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
 AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
 AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
 AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
 AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
 AddOutputFilterByType DEFLATE font/truetype font/opentype
</IfModule>

# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
 
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers
 
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off
 
# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header

Apache .htaccess添加/删除www到域重定向

# Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#RewriteCond %{HTTP_HOST} (.+)$ [NC]
#RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

#common configuration
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website\.it
RewriteRule ^(.*)$ http://www.website.it/$1 [R=301,L]
</IfModule>

Apache HTACCESS - 将所有其他用户重定向到即将推出的页面

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^12\.345\.67\.89
RewriteCond %{REQUEST_URI} !/coming-soon\.html$
RewriteRule (.*)$ /coming-soon.html [R=302,L]

Apache 停止目录索引浏览

Options All -Indexes

Apache 如何:保护您的WordPress博客免受热链接

RewriteEngine On 
#Replace ?mysite.com/ with your blog url 
RewriteCond %{HTTP_REFERER} !^http://(. .)?mysite.com/ [NC] 
RewriteCond %{HTTP_REFERER} !^$ 
#Replace /images/nohotlink.jpg with your "don't hotlink" image url 
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

Apache 使用.htaccess减少WordPress博客上的垃圾邮件

# BEGIN die spam die

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_METHOD} POST 
RewriteCond %{REQUEST_URI} .wp-comments-post.php* 
RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR] 
RewriteCond %{HTTP_USER_AGENT} ^$ 
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L] 
</IfModule>

# END die spam die