How to setting up your .htaccess for your application is always become a question which hard to answer. In this note, we will take a look at it, fully and detail by detail. Hope it to be useful.
The url rewrite configurations below will also be suitable for virtual hosting.
# Php settings # ==================== <IfModule php5_module> # Adjust memory limit # ======================== php_value memory_limit 64M # Adjust exec time to prevent overtime running # ================================ php_value max_execution_time 18000 # Make sure the default timezone is set # Can also be set within application using date_default_timezone_set # ===================================== php_value date.timezone "Asia/Shanghai" # Short tag for clean view scripts which is still not recommend # Because of the xml issue # ========================== php_value short_open_tag off # Default charset is utf-8 because of multi languages supportting # =============================== php_value default_charset "utf-8" # To report E_ALL|E_STRICT and show all errors # ============================== php_value error_reporting "8191" # Disable register globals which means nothing in php6 # =========================== php_flag register_globals off # Disable magic quotes which means nothing in php6 # =========================== php_flag magic_quotes_gpc off # Disable automatic session start but handled by program # e.g. Zend_Session::start() # ============================= php_flag session.auto_start off # Turn off compatibility with PHP4 # To avoid the problem when dealing with objects # ====================================== php_flag zend.ze1_compatibility_mode Off # Gzip output # ======================================= php_flag zlib.output_compression on php_value zlib.output_compression_level 9 # Disable user agent verification to not break multiple image upload # ================================== php_flag suhosin.session.cryptua off # output buffering # ============================= php_value output_buffering 4096 </IfModule> # Mime type # ==================== <IfModule mime_module> # Add javascript, php and phtml file type if needed # ========================================= AddType application/x-javascript .js AddType application/x-httpd-php .php .phtml # For 1and1 hosting issue, we use php5 for all # ========================== #AddType x-mapp-php5 .php #AddHandler x-mapp-php5 .php # For fastcgi mode # ========================================= #Action php5-cgi /cgi-bin/php5-cgi #AddHandler php5-cgi .php #cgi.fix_pathinfo = 1 # Default character encoding UTF-8 # ===================== AddDefaultCharset UTF-8 # No ETags for performance optimize # =========== FileETag none </IfModule> # Security scan # ======================= <IfModule mod_security.c> # Disable POST processing to not break multiple image upload # =================== SecFilterEngine Off SecFilterScanPOST Off </IfModule> # Expires by type # ====================== <IfModule mod_expires.c> # Add further expires for resources # =========================================================== ExpiresActive On ExpiresDefault "access plus 1 year" #ExpiresByType text/css "access plus 1 month" #ExpiresByType image/gif "access plus 1 month" #ExpiresByType image/jpeg "access plus 1 month" #ExpiresByType image/png "access plus 1 month" #ExpiresByType application/x-javascript "access plus 1 month" </IfModule> # Compress by type # ====================== <IfModule mod_deflate.c> # Default filter : deflate # ===================== SetOutputFilter DEFLATE # Netscape 4.x has some problems... # ========================================= BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems # ===================================== BrowserMatch ^Mozilla/4.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine # =============================================== BrowserMatch bMSIE !no-gzip !gzip-only-text/html # Do not compress images # =============================================================== SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary # The compress level 1(lowest)-9(highest) # ==================================================== #DeflateCompressionLevel 9 AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php # Make sure proxies do not deliver the wrong content # ====================== <IfModule mod_headers.c> Header append Vary User-Agent env=!dont-vary </IfModule> </IfModule> # Make HTTPS env vars available for CGI mode # ================== <IfModule mod_ssl.c> SSLOptions StdEnvVars </IfModule> # default index file # =================== <IfModule dir_module> # By default allow all access # ========================================== Options -Indexes -MultiViews +FollowSymLinks Order allow,deny Allow from all # Directory default index # =========================================== DirectoryIndex index.php index.html index.htm </IfModule> # Url rewrite # ====================== <IfModule mod_rewrite.c> # Rewrite enable # ============== RewriteEngine On # Rewrite base path to your site # =========== RewriteBase / # Forbidden access to htaccess file # ============================ RewriteRule ^.htaccess$ - [F] # Url canonicalization for SEO # ===================================================== RewriteCond %{HTTP_HOST} ^www.kimbs-local.info [NC] RewriteRule ^(.*)$ http://kimbs-local.info/$1 [L,R=301] RewriteCond %{HTTP_HOST} ^www.kimbs.info [NC] RewriteRule ^(.*)$ http://kimbs.info/$1 [L,R=301] # Rewrite for index if request is empty or did not mentioned before # ================================================================ RewriteCond %{REQUEST_URI} ="" RewriteCond %{REQUEST_URI} !^/(library/dojo)/ RewriteCond %{REQUEST_URI} !^/(library/fckeditor)/ RewriteCond %{REQUEST_URI} !^/(library/fckeditorPlugins)/ RewriteCond %{REQUEST_URI} !^/(library/syntaxhighlighter_2.0.320)/ RewriteRule ^.*$ /public/index.php [NC,L] # Rewrite for public if request is not the resource under public or did not mentioned before # ================================================================ RewriteCond %{REQUEST_URI} !^/public/.*$ RewriteCond %{REQUEST_URI} !^/(library/dojo)/ RewriteCond %{REQUEST_URI} !^/(library/fckeditor)/ RewriteCond %{REQUEST_URI} !^/(library/fckeditorPlugins)/ RewriteCond %{REQUEST_URI} !^/(library/syntaxhighlighter_2.0.320)/ RewriteRule ^(.*)$ /public/$1 # Never rewrite for existing files, directories and links # ============================================== RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^public/.*$ /public/index.php [NC,L] </IfModule>