Cheat Sheet for .htaccess
Posted by H9 Admin on 13 January 2015 04:09 PM
|
|
ackol's DenGreat cheatsheet for .htaccess with a good range of examples for most needs:http://www.thejackol.com/htaccess-cheatsheet/ ApacheOfficial documentation here: http://httpd.apache.org/docs/2.0/howto/htaccess.html Mod_Rewrite RulesOfficial documentation: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html Miscellaneous Helpful Links:http://www.htaccess-guide.com/ Redirect All Links to WWWSome site owners are concerned that users should always be redirected from sitename.com to www.sitename.com, or from mainsitename.com/addon to sitename.com. This can affect cookies, etc. IBBoard solved this issue with some .htaccess lines. RewriteEngine on RewriteCond %{HTTP_HOST} !^www.ibboard.co.uk$ RewriteCond %{THE_REQUEST} !^[^\]+\ /foldername(\?.*)?\ .*$ RewriteRule ^(.*)$ http://www.ibboard.co.uk/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^www.ibboard.co.uk$ RewriteRule ^$ http://www.ibboard.co.uk/ [R=301,L] Pseudo-descriptionCheck that the host doesn't match and check that the request isn't just the current folder without a trailing slash (or the current folder without a trailing slash with a query string) and then do a rewrite rule on that. The next rule then catches the host not maching but the request being /ibboard (i.e. some accessing www.hwtskins.co.uk/ibboard and not www.hwtskins.co.uk/ibboard/). Both rules then rewrite the request to use the required domain. The two rules are required as a single rule with only the %{HTTP_HOST} condition causes requests to "http://www.hwtskins.co.uk/ibboard" to be incorrectly rewritten to "http://www.ibboard.co.uk//home/username/public_html/ibboard". | |
|