Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /home2/learnera/public_html/tech/wp-includes/wp-db.php on line 760

Deprecated: Creation of dynamic property WPtouchProFour::$settings_object is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/wptouch/core/class-wptouch-pro.php on line 82

Deprecated: Automatic conversion of false to array is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/wptouch/core/admin-load.php on line 70

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property WP_Block_Type::$skip_inner_blocks is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-block-type.php on line 391

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_classic_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 347

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 349

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$toolbar_block_side is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 350

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$panels_block is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 351

Deprecated: Creation of dynamic property Advanced_Editor_Tools::$used_block_buttons is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 354

Deprecated: Creation of dynamic property YARPP::$is_custom_template is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/yet-another-related-posts-plugin/classes/YARPP_Core.php on line 56

Deprecated: Creation of dynamic property YARPP::$db_options is deprecated in /home2/learnera/public_html/tech/wp-content/plugins/yet-another-related-posts-plugin/classes/YARPP_Core.php on line 69

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /home2/learnera/public_html/tech/wp-includes/class-wp-term-query.php on line 1118

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723

Warning: Cannot modify header information - headers already sent by (output started at /home2/learnera/public_html/tech/wp-includes/wp-db.php:760) in /home2/learnera/public_html/tech/wp-includes/rest-api/class-wp-rest-server.php on line 1723
{"id":501,"date":"2014-10-05T02:39:56","date_gmt":"2014-10-05T02:39:56","guid":{"rendered":"http:\/\/tech.learnerandtutor.com\/?p=501"},"modified":"2014-10-05T02:47:04","modified_gmt":"2014-10-05T02:47:04","slug":"htaccess-in-detail","status":"publish","type":"post","link":"http:\/\/tech.learnerandtutor.com\/htaccess-in-detail\/","title":{"rendered":".htaccess in Detail"},"content":{"rendered":"

What is .htacces file?<\/h2>\n

.htaccess are files (or “distributed configuration files”) which provide a way to make configuration changes on a per-directory basis.<\/p>\n

With the use of .htaccess file we can acheive the\u00a0 below tasks.
\nmake password product, redirect, script enable, index listing, index file.<\/p>\n

Is it safe?<\/h2>\n

There are two main reasons to avoid the use of .htaccess files.<\/p>\n

The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.<\/p>\n

Further note that Apache must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. (See section on how directives are applied.) Thus, if a file is requested out of a directory \/www\/htdocs\/example, Apache must look for the following files:<\/p>\n

\/.htaccess
\n\/www\/.htaccess
\n\/www\/htdocs\/.htaccess
\n\/www\/htdocs\/example\/.htaccess<\/p>\n

And so, for each file access out of that directory, there are 4 additional file-system accesses, even if none of those files are present. (Note that this would only be the case if .htaccess files were enabled for \/, which is not usually the case.)<\/p>\n

The second consideration is one of security. You are permitting users to modify server configuration, which may result in changes over which you have no control. Carefully consider whether you want to give your users this privilege. Note also that giving users less privileges than they need will lead to additional technical support requests. Make sure you clearly tell your users what level of privileges you have given them. Specifying exactly what you have set AllowOverride to, and pointing them to the relevant documentation, will save yourself a lot of confusion later.<\/p>\n

To enable .htaccess, change the AllowOverride option in the apache conf file accordingly<\/p>\n

AllowOverride All<\/pre>\n

Instead of All we can give Options FileInfo, AuthConfig, Limit and None<\/p>\n

The default filename is .htaccess. If we want to change change in the apache httpd.conf file as below.<\/p>\n

AccessFileName .config<\/pre>\n

If you changed the above settings .htaccess enabled. So now place a file with name .htaccess (or any given name) in the web server root directory.<\/p>\n

Before processing that directory apache will look for a file named .htaccess there before doing any processing. If parent directory\u00a0 and sub directory contains same configuration info for sub directory sub directory configuration will be taken.<\/p>\n

Useful commands<\/h2>\n

If file not found error occurred in the directory we can set the default error page to something.<\/p>\n

ErrorDocument 404 \/404.html<\/pre>\n

As mentioned above we can apply the same concept for other error codes also. For example 500 for internal server error, 403 for access denied.<\/p>\n

To disable directory indexes inside the directory add below line to .htaccess file<\/p>\n

 Options -Indexes<\/pre>\n

To allow particulat ip address add below code<\/p>\n

allow from 192.168.5.26<\/pre>\n

[ Range can also possible like 000.000.000.000,192.168.000.000 ]<\/p>\n

To deny particular ip address<\/p>\n

deny from 192.168.5.26<\/pre>\n

[ Range can also possible like 000.000.000.000,192.168.000.000 ]<\/p>\n

To deny from all<\/p>\n

deny from all<\/pre>\n

To specify index file for each folder<\/p>\n

DirectoryIndex index.html index.jsp index.php<\/pre>\n

Apache will look from left to right, So if index.html not found it will look for index.jsp then index.php<\/p>\n

Also we can redirect a particular directory or particular file to another path\/file in the same server or on any other server. See below<\/p>\n

To Redirect file\/path<\/p>\n

 Redirect \/path\/file \/newpath\/file<\/pre>\n
Redirect \/file http:\/\/www.google.com<\/pre>\n

While doing redirect the additional info in the path will be kept as it is. For example after\u00a0Redirect \/test http:\/\/www.google.com\/test<\/span>\u00a0 if we type\u00a0www.oldurl.com\/test\/filepath\/file.png<\/span>\u00a0 it will go to www.google.com\/test\/filepath\/file.png<\/span><\/p>\n

To protect a directory with password add below code<\/p>\n

AuthName \"Name to display while prompting password\"\r\nAuthType Basic\r\nAuthUserFile \"\/full\/path\/to\/.htpasswd\"\r\nRequire valid-user<\/pre>\n

To add the password and user details to .htpasswd file use the htpasswd command as below.<\/p>\n

htpasswd -mc \/full\/path\/to\/.htpasswd username<\/pre>\n

To access the path via script directly with password try with http:\/\/rajesh:rajesh123@localhost\/test<\/span><\/p>\n

Find the options available with htpasswd command to create password below.<\/p>\n

htpasswd [ -c ] [ -m ] [ -D ] passwdfile username\r\nhtpasswd -b [ -c ] [ -m | -d | -p | -s ] [ -D ] passwdfile username password\r\nhtpasswd -n [ -m | -d | -s | -p ] username\r\nhtpasswd -nb [ -m | -d | -s | -p ] username password<\/pre>\n

-b\u00a0\u00a0 \u00a0Use batch mode; i.e., get the password from the command line rather than prompting for it. This option should be used with extreme care, since the password is clearly visible on the command line.<\/p>\n

-c\u00a0\u00a0 \u00a0Create the passwdfile. If passwdfile already exists, it is rewritten and truncated. This option cannot be combined with the -n option.<\/p>\n

-n\u00a0\u00a0 \u00a0Display the results on standard output rather than updating a file. This is useful for generating password records acceptable to Apache for inclusion in non-text data stores. This option changes the syntax of the command line, since the passwdfile argument (usually the first one) is omitted. It cannot be combined with the -c option.<\/p>\n

-m\u00a0\u00a0 \u00a0Use MD5 encryption for passwords. This is the default (since version 2.2.18).<\/p>\n

-d\u00a0\u00a0 \u00a0Use crypt() encryption for passwords. This is not supported by the httpd server on Windows and Netware and TPF. This algorithm limits the password length to 8 characters. This algorithm is insecure by today’s standards. It used to be the default algorithm until version 2.2.17.<\/p>\n

-s\u00a0\u00a0 \u00a0Use SHA encryption for passwords. Facilitates migration from\/to Netscape servers using the LDAP Directory Interchange Format (ldif).<\/p>\n

-p\u00a0\u00a0 \u00a0Use plaintext passwords. Though htpasswd will support creation on all platforms, the httpd daemon will only accept plain text passwords on Windows, Netware and TPF.<\/p>\n

-D\u00a0\u00a0 \u00a0Delete user. If the username exists in the specified htpasswd file, it will be deleted.<\/p>\n

passwdfile\u00a0\u00a0 \u00a0Name of the file to contain the user name and password. If -c is given, this file is created if it does not already exist, or rewritten and truncated if it does exist.<\/p>\n

username\u00a0\u00a0 \u00a0The username to create or update in passwdfile. If username does not exist in this file, an entry is added. If it does exist, the password is changed.<\/p>\n

password\u00a0\u00a0 \u00a0The plaintext password to be encrypted and stored in the file. Only used with the -b flag.<\/p>\n","protected":false},"excerpt":{"rendered":"

What is .htacces file? .htaccess are files (or “distributed configuration files”) which provide a way to make configuration changes on a per-directory basis. With the use of .htaccess file we can acheive the\u00a0 below tasks. make password product, redirect, script … Continue reading →<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28],"tags":[22,29],"_links":{"self":[{"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/posts\/501"}],"collection":[{"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/comments?post=501"}],"version-history":[{"count":12,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/posts\/501\/revisions"}],"predecessor-version":[{"id":514,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/posts\/501\/revisions\/514"}],"wp:attachment":[{"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/media?parent=501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/categories?post=501"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tech.learnerandtutor.com\/wp-json\/wp\/v2\/tags?post=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}