Apache
From Marketing Wiki
Contents |
Installing Apache
- Apache2triad - Install Apache, PHP, MySQL and more on Windows with just a few clicks.
mod_rewrite and .htaccess
- .htaccess Cheat Sheet - iLoveJackDaniels.com Cheatsheet
- .htaccess tips - Apache.org
- mod_rewrite docs - Apache.org
- mod_rewrite Tutorial - WorkingWith.me.uk
- .htaccess Guide - JavaScriptKit.com
- Ultimate .htaccess Examples - Evolt.org
- Stupid .htaccess Tricks - PerishablePress.com's comprehensive .htaccess page
.htaccess Recipes
Prevent Directory Listings
Options All -Indexes
Block IP Addresses
Replace nn.nnn.nnn.nnn with the actual IP addresses that you want to ban:
order allow,deny deny from nn.nn.nn.nnn deny from nn.nn.nnn.nn deny from nn.nnn.nnn.nnn allow from all
Remove Trailing Slashes
RewriteRule ^(.*[^/])/$ /$1 [R=301,L]
301 Redirect
This will 301 redirect one page to another:
RewriteRule ^the-old-page$ http://example.com/the-new-page [R=301,L]
Redirect Query Strings
If the URL has a query string it needs a different kind of redirect rule:
RewriteCond %{QUERY_STRING} p=the-query-string RewriteRule ^index\.php$ /the-new-pages.html? [R=301,L]
The above rule would redirect example.com/index.php?p=the-query-string to example.com/the-new-page.html.
Canonical URLs
The following rule redirect from the non-www version of a domain name to the www version, e.g., from example.com to www.example.com:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This variation does the same, but says "if it's anything but www then redirect to the www":
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This redirect from the www to the non-www:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule (.*) http://example.com/$1 [R=301,L]
