To know about more basic of .htaccess file click here.
For example, if you had downloaded some photos on your website under the path – /album/ and want to share photos with your ONLY girlfriend named Jessica, this name must be specified. The first thing you need to do is create a file called .Htpasswd or something you love. You can use the httpd built-in program with the Apache .htpasswd.
The program prompts for the password Jessica user and an .Htpasswd is created and stored in the path /local/usr/.Htpasswd.
htpasswd –c /local/usr/.htpasswd Jessica
Second, you need to create the .htaccess file and place it in the album directory with the following content.:
AuthType BasicAuthName EnterPasswordAuthUserFile /local/usr /.HtpasswdRequire user Jessica
The code fragment above indicates that it will use basic authentication to authenticate the user, and only Jessica user is allowed to access the album directory.
Enabling SSI (Server-Side Includes)
How many pages do you have in your website? Maybe a few dozen, right? And each page has the same header, navigation menu, footer and copyright information. What will you do if you want to add a menu item? It’s a nightmare for you, right? If you use SSI, you just make the change once all the pages will change. Does that sound useful?
Ok, let’s do it.
AddType text/html ShtmlAddHandler analyzed by the server .Shtml
The guidelines above indicate that the files with the extension. Shtml are text / html will be parsed by the server.
For example you have a page in your products – products.shtml:
Blocking change and redirects
When you find someone who wants to hack your site, it does not matter; just block his IP or IP range.
To deny Allow
Deny from 10.133.11.110
allow from all
The above excerpt directive will block requests from IP 10.133.11.110 and an IP address that begins with 10 188.
Would you use a JSP script to create your dynamic website, and we will add to the page index.jsp home directory by default.
DirectoryIndex index.html index.htm index.shtml index.jsp default.cgi
By setting the above directive in your .Htaccess file, when a request comes from a directory, the server will attempt to locate the files from left to right as the page’s default directory.
The last characteristic is the widespread use of url redirect. Redirect feature is more useful than .htaccess offer, either on the same server or on a completely different website. It can be extremely useful if you change the name of one of your files, but still allows users to find it. Another use that I find very useful is to redirect to a URL longer, for example:
To show you another example, suppose your current domain is yoursite. com website and now you have registered another domain yoursite. net, and you expect any requests to yoursite. net will be forwarded to yoursite. com. This means that the entire site redirects, so you must add a “monitoring” of the Directive .htaccess and place it at the root of yoursite. net.
Redirect / http://www. example. com/
When a user requests a URL, for example http://www. yoursite. net/news/daily.html, the browser’s address will be forwarded to http://www. yoursite. com/news/daily.html. Also a request http://www. yoursite. net/album/index.jsp will be forwarded to http://www. yoursite. com/album/index.jsp.
Meta tag redirection
Now that you’ve seen the basic functionality that the .htaccess file provides. Let’s talk about another way to redirect the use of meta tags.
Home of your old site would be updated with the above code. All users who come to the root of the old site will be routed to the new site, http://www.example.com after 5 seconds.
Advantages and disadvantages
Now that you have watched the two files using .htaccess redirect server-side approaches. And Meta tags, we will discuss their advantages and disadvantages.
Advantages and disadvantages of the use of meta tag redirect:
Have control over the redirection without any intervention from the system administrator.
You can educate the user on changing the site. You can see a change notification to the user and then redirect to the new site.
Some of the disadvantages
The redirection is only supported by certain browsers like Internet Explorer, Firefox and Netscape – in other words, only the popular browsers. If you plan to use a redirect like this, you should include a link to the site so that users with browsers that do not support redirection meta tag, can follow the link.
The redirect works only for the specific page that contains the meta tag. If the user comes to your site looking for multiple pages, you will need to create landing pages for each page of the site.
Some search engines may not recognize the redirect meta tag.
Advantages and disadvantages of using an .htaccess redirect:
The redirection is transparent and does not cause any disruption to your users.
You can use a redirect to a file, directory and web sites, even together.
The redirection is not dependent on browser.
The redirection can still be recognized by search engines.
Some of the disadvantages
.htaccess only works in the Apache server. This means that if your site is hosted by NT server, the .htaccess file will not work.
.htaccess will lead to problems with server performance. For example, if you have enabled .htaccess in your site http://www. yoursite. com/album/childhood/single/index.html user requests, since you have selected .htaccess file the server will try to locate the .htaccess file in the following ways:
And so, for each file access that directory, there are four other access to the file system, even if none of these files are present.
Please note, however, the following security issues. If you turn .htaccess to change the server configuration, this can lead to changes over which you have no control. Carefully consider whether you want to give your users this privilege.
If your site is on the Apache server and need .htaccess to be enabled, then .htaccess redirect is better than the Meta tag redirect based on the advantages and disadvantages of comparison.