apache_conf 一套方便的.htaccess声明,我可以为各种项目挑选

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf 一套方便的.htaccess声明,我可以为各种项目挑选相关的知识,希望对你有一定的参考价值。

SetEnv APPLICATION_ENV development
SetEnv DEBUG_FIREPHP enabled
# Access in PHP: 
# // Define application environment
# defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
# // Enable FirePHP for testing?
# defined('DEBUG_FIREPHP') || define('DEBUG_FIREPHP', (getenv('DEBUG_FIREPHP') ? getenv('DEBUG_FIREPHP') : 'disabled'));

Options All -Indexes
Options +FollowSymLinks

# SET DEFAULT CHARACTER SET AND LANGUAGE
AddDefaultCharset UTF-8
AddLanguage en-US .html .htm .xhtml .css .js .xml
# EXTRA CHARSET DECLARATION FOR XML DOCS
<FilesMatch "\.(xml)$">
AddDefaultCharset UTF-8
DefaultLanguage en-US
</FilesMatch>

# FORCE DOWNLOAD OF CERTAIN FILE TYPES
<Files *.xls>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</Files>
<Files *.eps>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</Files>

# STATIC ERROR FILES
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html

<IfModule mod_rewrite.c>
# TURN ON MOD REWRITE
	RewriteEngine On
	RewriteBase /
# CANONICALIZE DOMAIN NAME
	RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
	RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# PREVENT FAVICON EXPLOIT
 RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC]
 RewriteCond %{REQUEST_URI} favicon\.ico [NC]
 RewriteRule (.*) http://www.example.com/favicon.ico [R=301,L] 
</IfModule>

# SET HIGHER MEMORY AND UPLOAD LIMITS FOR PHP
php_flag file_uploads On
php_value memory_limit 64M
php_value post_max_size 16M
php_value upload_max_filesize 16M

# PROTECT PRIVATE FILES
<Files ~ "^.*\.([Ll][Oo][Gg]|[Dd][Aa][Tt]|[Hh][Tt][Aa])">
 order allow,deny
 deny from all
</Files>

# DEFLATE FOR APACHE 2.x SERVERS
<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript application/javascript application/xhtml+xml application/x-font application/vnd.ms-fontobject
	<FilesMatch "\\.(js|css|html|htm|xml|eot|svg|ttf|otf)$">
	SetOutputFilter DEFLATE
	</FilesMatch>
</IfModule>

# SUPPRESS PHP ERRORS
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

# ~~~~ SET ^MIME TYPES TO PREVENT CONTENT ISSUES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    # ~ Common types
        AddType application/javascript          js
        AddType text/css                        css
    # ~ HTC Files (for IE hacks)
        AddType text/x-component                htc
    # ~ audio
        AddType audio/ogg                       oga ogg
        AddType audio/mp4                       m4a
    # ~ video
        AddType video/ogg                       ogv
        AddType video/mp4                       mp4 m4v
        AddType video/webm                      webm
    # ~ SVG
        AddType image/svg+xml                   svg svgz
        AddEncoding gzip                        svgz
    # ~ Webfonts
        AddType application/vnd.ms-fontobject   eot
        AddType font/ttf                        ttf ttc
        AddType font/otf                        otf
        AddType font/x-woff                     woff
    # ~ Other
        AddType text/calendar                   ics
        AddType image/x-icon                    ico
        AddType image/webp                      webp
        AddType text/cache-manifest             appcache manifest
        AddType application/x-chrome-extension  crx
        AddType application/x-xpinstall         xpi
        AddType application/octet-stream        safariextz
        AddType text/x-vcard                    vcf

# Force the latest IE version, in various cases when it may fall back to IE7 mode
#  github.com/rails/rails/commit/123eb25#commitcomment-118920
<IfModule mod_setenvif.c>
     <IfModule mod_headers.c>
          BrowserMatch MSIE ie
          Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
     </IfModule>
</IfModule>

# REDIRECT .htc FILE REQUESTS TO CENTRAL LOCATION BECAUSE IE IS STUPID
#<ifmodule mod_rewrite.c>
# RewriteEngine on
# RewriteCond %{REQUEST_URI} !^/PIE\.htc [NC]
# RewriteCond %{REQUEST_URI} PIE\.htc [NC]
# RewriteRule (.*) http://domain.tld/PIE.htc [R=301,L] 
#</ifmodule>


# Removes index.php from ExpressionEngine URLs
#<ifmodule mod_rewrite.c>
# RewriteEngine on
# RewriteCond $1 !\.(gif|jpe?g|png|webp|svgz?|tt.|eot|woff|otf|htc|mp.|m4.|og.|flv)$ [NC]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ /index.php/$1 [L]
#</ifmodule>

以上是关于apache_conf 一套方便的.htaccess声明,我可以为各种项目挑选的主要内容,如果未能解决你的问题,请参考以下文章

apache_conf 一套方便的.htaccess声明,我可以为各种项目挑选

apache_conf 使用和配置Google Ajax Crawler以方便搜索引擎索引ajax富页面(客户端MVC和Google Ajax Crawli)

text htacces

markdown htacces.md

.htacces-清除URL

text Wordpress .htacces重定向到https