AddType application/x-httpd-php .html
Tag Archive for htaccess
Parse HTML files as PHP
Redirect A Single Page To HTTPS Using mod_rewrite
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ <a href="http://www.example.com/$1" >http://www.example.com/$1</a> [r=301,nc]
rewritecond %{SERVER_PORT} !^443$
rewriterule ^filename.php(.*)$ <a href="https://www.example.com/filename.php$1" >https://www.example.com/filename.php$1</a> [r=301]
Replace _ with – in almost every url (plus nice tag urls in movabletype)
RewriteEngine On RewriteRule ^tag/?$ /browse.html [L] RewriteRule ^tag/(.*)$ /mt/mt-search.cgi?tag=$1&blog_id=1&IncludeBlogs=1 [L] RewriteRule ^mt-static(.*)$ - [L] RewriteRule ^(.*)_(.*)$ $1-$2 [N]
Forward from domain aliases to main domain
# forward from domain aliases
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?domain2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?domain3.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www.)?and_so_on.com [NC]
RewriteRule (.*) <a href="http://maindomain.com/$1" >http://maindomain.com/$1</a> [R=301,L]
# END forward from domain aliases
Force removal of WWW in url
# force removal of www IN URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ <a href="http://example.com/$1" >http://example.com/$1</a> [R=301,L]
# END force removal of www IN URL# force www IN URL
Force WWW in url
# force www in url
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ <a href="http://www.example.com/$1" >http://www.example.com/$1</a> [R=301,L]
# END force www in url
Cache Control with htaccess EXPIRES BY TYPE
# Cache Control with .htaccess EXPIRES BY TYPE # from <a href="http://forum.powweb.com/showthread.php?t=62786" >http://forum.powweb.com/showthread.php?t=62786</a> ### turn on the Expires engine ExpiresActive On ### expires after a month in the client's cache ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType application/pdf A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType text/plain A2592000 ### expires after 4.8 hours ExpiresByType text/css A17200 # Please note that the "A" before the numbers above stands for Access. # This means that the stopwatch starts when a client accesses the file. # You can also use "M" for modified. # TIME CHEAT SHEET # 300 5 MIN # 600 10 MIN # 900 15 MIN # 1800 30 MIN # 2700 45 MIN # # 3600 1 HR # 7200 2 HR # 10800 3 HR # 14400 4 HR # 18000 5 HR # 36000 10 HR # 39600 11 HR # 43200 12 HR # 46800 13 HR # 50400 14 HR # 54000 15 HR # 86400 24 HR # # 86400 1 DAY # 172800 2 DAY # 259200 3 DAY # 345600 4 DAY # 432000 5 DAY # 518400 6 DAY # 604800 7 DAY # # 604800 1 WEEK # 1209600 2 WEEK # 1814400 3 WEEK # 2419200 4 WEEK # # 2419200 1 MONTH (FEBRUARY) # 2505600 1 MONTH (FEBRUARY LEAP YEAR) # 2592000 1 MONTH (APRIL, JUNE, SEPTEMBER, NOVEMBER) # 2678400 1 MONTH (JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER) # 31536000 12 MONTH
Cache Control with htaccess FILES MATCH
# Cache Control with .htaccess # from <a href="http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html" >http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html</a> # 3 Month <FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$"> Header set Cache-Control "max-age=7257600" </FilesMatch> # 1 Week <FilesMatch ".(js|css|pdf|txt)$"> Header set Cache-Control "max-age=604800" </FilesMatch> # 10 Minutes <FilesMatch ".(html|htm)$"> Header set Cache-Control "max-age=600" </FilesMatch> # NONE <FilesMatch ".(pl|php|cgi|spl)$"> Header unset Cache-Control Header unset Expires Header unset Last-Modified FileETag None Header unset Pragma </FilesMatch> # TIME CHEAT SHEET # 300 5 MIN # 600 10 MIN # 900 15 MIN # 1800 30 MIN # 2700 45 MIN # # 3600 1 HR # 7200 2 HR # 10800 3 HR # 14400 4 HR # 18000 5 HR # 36000 10 HR # 39600 11 HR # 43200 12 HR # 46800 13 HR # 50400 14 HR # 54000 15 HR # 86400 24 HR # # 86400 1 DAY # 172800 2 DAY # 259200 3 DAY # 345600 4 DAY # 432000 5 DAY # 518400 6 DAY # 604800 7 DAY # # 604800 1 WEEK # 1209600 2 WEEK # 1814400 3 WEEK # 2419200 4 WEEK # # 2419200 1 MONTH (FEBRUARY) # 2505600 1 MONTH (FEBRUARY LEAP YEAR) # 2592000 1 MONTH (APRIL, JUNE, SEPTEMBER, NOVEMBER) # 2678400 1 MONTH (JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER) # 31536000 12 MONTH
Clean URL
<?php
$urlArray = explode("/",$_SERVER["REQUEST_URI"]);
$url_what = $urlArray[count($urlArray)-1];
if($url_what == 'home') {
// rather than index.php?act=home, url would be index/home
displayHome();
}elseif($url_what == 'contact'){
// rather than index.php?act=contact,url will be index/contact
displayContact();
}elseif($url_what == 'calendar'){
// rather than index.php?act=calendar,url will be index/calendar
displayCalendar();
}elseif($url_what == 'about'){
// rather than index.php?act=about,url will be index/about
displayAbout();
}else
//if $url_what doesn't exist, display home
writeHome();
?>
Force SSL HTTPS Connections
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ <a href="https://www.domain.com/$1" >https://www.domain.com/$1</a> [R,L]