Apache .htaccess规则允许在Firefox中跨站点嵌入字体共享

# example Apache .htaccess file to add access control header
 
<FilesMatch "\.(ttf|otf)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

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 停止,启动或重新启动apache

#in ubuntu terminal 

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start


sudo /etc/init.d/apache2 restart

Apache 别名.htaccess重定向301

# Redirect alias
RewriteCond %{HTTP_HOST} ^www.example.net$ [OR]
RewriteCond %{HTTP_HOST} ^example.net$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC,L]

Apache Wordpress的效率更高效HTACCESS / mod_rewrite

# BEGIN WordPress
RewriteEngine on
#
# Unless you have set a different RewriteBase preceding this
# point, you may delete or comment-out the following
# RewriteBase directive:
RewriteBase /
#
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
#
# END wordpress

Apache 将访问者重定向到目录

Redirect /olddir http://www.domainname.com/newdir/

Apache htaccess否认所有人

# no one gets in here!
deny from all

Apache htaccess性能规则

# Begin performance rules

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<ifModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
</ifModule>

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 3 months"
  ExpiresByType image/jpeg "access plus 3 months"
  ExpiresByType image/png "access plus 3 months"
  ExpiresByType image/ico "access plus 3 months"
  ExpiresByType image/icon "access plus 3 months"
  ExpiresByType image/x-icon "access plus 3 months"
  ExpiresByType text/css "access plus 3 months"
  ExpiresByType text/javascript "access plus 3 months"
  ExpiresByType application/x-javascript "access plus 3 months"
</ifModule>



<ifModule mod_headers.c>
	Header unset ETag
	Header unset Last-Modified
	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4|js|css)$">
	Header set Cache-Control "public, no-transform"
	</FilesMatch>

</ifModule>
FileETag None

#end performance rules

Apache 保护要读取的htaccess文件

# secure htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

Apache 将domainname.tld更改为www.domainname.tld

## Changes domainname.tld into www.domainname.tld
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domainname\.com$ [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301]
RewriteRule ^(.*)\.html$ $1.php [R=301,L]