{"id":294,"date":"2011-03-04T13:18:46","date_gmt":"2011-03-04T02:18:46","guid":{"rendered":"http:\/\/howden.net.au\/thowden\/?p=294"},"modified":"2011-03-04T13:18:46","modified_gmt":"2011-03-04T02:18:46","slug":"htaccess-useful-options","status":"publish","type":"post","link":"https:\/\/howden.net.au\/thowden\/2011\/03\/htaccess-useful-options\/","title":{"rendered":".htaccess useful options"},"content":{"rendered":"<p>This is a post that I started to remind me of what the correct syntax is for the .htaccess file. But given that it has kind of grown to include a heap of .htaccess info I thought it wise to highlight the <a href=\"http:\/\/httpd.apache.org\/docs\/trunk\/howto\/htaccess.html\">Apache official .htaccess tutorial pages<\/a>. Given the information in that tutorial only use .htaccess if you really need to and preferably use the correct httpd.conf (apache2.conf or similar depending on your distro) for the commands as it will help with system performance.  That said, there are a number of things that I use .htaccess for, here are some of them.<\/p>\n<p>Edit: Have not read this as yet, but it seems to contain a heap more detail. <a href=\"http:\/\/www.askapache.com\/htaccess\/htaccess.html\">http:\/\/www.askapache.com\/htaccess\/htaccess.html<\/a><\/p>\n<p>The following came from <a href=\"http:\/\/www.buildwebsite4u.com\/advanced\/htaccess-file.shtml\">http:\/\/www.buildwebsite4u.com\/advanced\/htaccess-file.shtml<\/a>:<\/p>\n<p>Redirecting YourSite.com to www.YourSite.com<br \/>\nIf search engines find both www and non-www links from other sites to your site, they may treat http:\/\/YourSite.com and http:\/\/www.YourSite.com as two different websites with the same content. This means that your site can be penalized for duplicate content. Many experts recommend to set up a 301 redirect (permanent redirect) from YourSite.com to www.YourSite.com&#8230;<\/p>\n<p>The code for this would be:<br \/>\n[php]<br \/>\nRewriteEngine On<br \/>\nRewriteCond %{HTTP_HOST} ^YourSite.com [nc]<br \/>\nRewriteRule (.*) http:\/\/www.YourSite.com\/$1 [R=301,L][\/php]<\/p>\n<p>Of course, using the .htaccess file and having all the correct paths enabled will help.<\/p>\n<p>My default SME Server uses Apache2 and I have found that in order to use .htaccess and htpasswd effectively I had to add \/ enable some modules in the \/etc\/httpd\/conf\/httpd.conf file.<\/p>\n<p>Setting aside the fact that SME Server needs to have specific templates updated, the Centos distro that it is based on will be similar to this (I expect).<\/p>\n<p>I did enable a number of auth type modules to address a number of errors.\u00a0 In each case the \/var\/log\/httpd\/error.log was where the errors were recorded.<\/p>\n<blockquote><p>.htaccess: Invalid command &#8216;AuthUserFile&#8217;, perhaps misspelled or defined by a module not included in the server configuration<\/p><\/blockquote>\n<p>was fixed by enabling<\/p>\n<blockquote><p>LoadModule authn_file_mod modules\/mod_authn_file.so<\/p><\/blockquote>\n<p>While the error<\/p>\n<blockquote><p>configuration error:  couldn&#8217;t check user.  No user file?<\/p><\/blockquote>\n<p>needed to have the Basic Authentication module enabled in the LoadModules section of the httpd.conf<\/p>\n<blockquote><p>LoadModule auth_basic_mod modules\/mod_auth_basic.so<\/p><\/blockquote>\n<p>needed to have Basic Authentication enabled.  Note that by default Digest is enabled but given that Digest provides little security above Basic I am ok with using Basic with SSL. Note that the SSL is essential for Basic Authentication to be of use. <a href=\"http:\/\/httpd.apache.org\/docs\/current\/howto\/auth.html\">Read the info from Apache on Basic v Digest<\/a> as I think it makes it clear.<\/p>\n<p>&#8230;and another error<\/p>\n<blockquote><p>configuration error:  couldn&#8217;t check access.  No groups file?:<\/p><\/blockquote>\n<p>needed to have this module added.<\/p>\n<blockquote><p>LoadModule authz_user_mod modules\/mod_authz_user.so<\/p><\/blockquote>\n<p>at this point I could login from the browser and got a prompt to access the directory. However there was still an error in the log which stated:<\/p>\n<blockquote><p>\/.htaccess: order not allowed here<\/p><\/blockquote>\n<p>This was because I had not completed the AllowOverride construct in the httpd.conf file.<\/p>\n<p>In my httpd.conf I have sections for each virtual site \/ directory on the server.<\/p>\n<blockquote><p>\nOptions None<br \/>\nOptions +Indexes<br \/>\nOptions +Includes<br \/>\nAllowOverride None<br \/>\norder deny,allow<br \/>\ndeny from all<br \/>\nallow from all\n<\/p><\/blockquote>\n<p>in which the &#8216;AllowOverride None &#8216; directive will ignore .htacess, while setting it to AllowOverride AuthConfig will allow it to check for a username\/password it also needs the AllowOverride Limit to avoid the error about Order.<\/p>\n<p>So to summarise the httpd.conf change I added a specific directory directive for the directory I am securing with htaccess\/ htpasswd with the following:<\/p>\n<blockquote><p>\nAllowOverride AuthConfig Limit<br \/>\norder deny,allow<br \/>\ndeny from all<br \/>\nallow from all\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>.htaccess apache settings<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,21],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-apache","category-web-sites"],"_links":{"self":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":0,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"wp:attachment":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}