{"id":255,"date":"2011-10-16T22:08:04","date_gmt":"2011-10-17T05:08:04","guid":{"rendered":"http:\/\/virendrachandak.wordpress.com\/?p=255"},"modified":"2015-02-20T16:37:06","modified_gmt":"2015-02-21T00:37:06","slug":"more-htaccess-tips","status":"publish","type":"post","link":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/","title":{"rendered":"more .htaccess tips"},"content":{"rendered":"<p>In my previous post <a title=\".htaccess tips\" href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/htaccess-tips\/\" target=\"_blank\"><strong>.htaccess tips<\/strong><\/a> I had started with what is .htaccess file and some things that can be done using it. In this post I&#8217;ll cover more about .htaccess files.<\/p>\n<p>Topics Covered:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#dir_index\">Directory index file<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#htaccess_redirection\">Redirection<\/a>\n<ul>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#www_nonwww\">Preferred domain (www or non-www)<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_domain\">Redirect old site to new site<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_dir\">Redirect all files in a directory<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_file\">Redirect a file in a directory<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#change_extension\">Changing\/displaying different file extension<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_url_string\">Redirect a URL having complete query string<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_url_string_start\">Redirect a URL starting with specific query string<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_url_string_contained\">Redirect a URL containing specific query string<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#redirect_ipaddress\">Redirect based on ipaddress<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#ban_ip\">Ban visitors from specific ipaddress<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#ban_referrers\">Ban visitors referred from certain sites<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#private_site\">Allow visitors only from specific ipaddress<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#disable_hotlinking\">Disable Hotlinking<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#multi_domain\">Multiple domains on same file system<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#flags\">Some RewriteRule Flags<\/a><\/li>\n<li><a href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/more-htaccess-tips\/#php_variables\">Change PHP Flags<\/a><\/li>\n<\/ul>\n<p><!--more--><\/p>\n<div id=\"dir_index\" style=\"padding-top:30px;\">\n<h3>Directory index file<\/h3>\n<p>When a user request a URL like <code>http:\/\/www.example.com\/test_dir\/<\/code> we would want to display an index file. i.e. the user will be able to view <code>http:\/\/www.example.com\/test_dir\/index.php<\/code> just by visiting <code>http:\/\/www.example.com\/test_dir\/<\/code><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tDirectoryIndex index.php\r\n<\/pre>\n<p>If we want to create fallback options i.e. if index.php does not exists server index.html, then we can use the following. The order in which the files are specified will be the order in which Apache will look for those files.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tDirectoryIndex index.php index.html index.htm\r\n<\/pre>\n<\/div>\n<div id=\"htaccess_redirection\" style=\"padding-top:30px;\">\n<h3>Redirection using .htaccess file<\/h3>\n<p>.htaccess file can be used to redirect users from old site to new site, to a preferred domain, etc. To do this we use 301 redirects. 301 is HTTP Status Code meaning Moved Permanently. This indicates that the page was moved from the original location.<\/p>\n<p><span style=\"text-decoration:underline;\"><strong>Note<\/strong><\/span>: 301 redirects (or Permanent Redirect) should be used only if you are permanently moving to a new domain or moving a page to new location. If you are moving the page temporarily then you should use 302 (or Temporary Redirect) to redirect to the temporary new location.<\/p>\n<p>There is no limit on how many redirects can be done per site or per domain. Also, you can make a page redirect to another and then that page to another and create chain of such redirects. This is not recommended. It is always best to have just 1 or 2 hops in the redirect chain, because most search engine crawlers will stop following the redirects after 3-4 hops. So, the lesser number of hops in the chain redirects the better it is.<\/p>\n<div id=\"www_nonwww\" style=\"padding-top:30px;\">\n<h3>Preferred domain (www or non-www)<\/h3>\n<p>Websites http:\/\/www.example.com and http:\/\/example.com are considered different websites by search engines. So it is always better to have on domain as preferred domain for the site.<\/p>\n<p><strong>Redirect non www to www version of site<\/strong>: All users will be redirected to <code>http:\/\/www.example.com<\/code> even if they use the URL <code>http:\/\/example.com<\/code><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{HTTP_HOST} ^example.com\r\n\tRewriteRule (.*) http:\/\/www.example.com\/$1 &#x5B;R=301,L]\r\n<\/pre>\n<p><strong>Redirect www to non www version of site<\/strong>: All users will be redirected to <code>http:\/\/example.com<\/code> even if they use the URL <code>http:\/\/www.example.com<\/code><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{HTTP_HOST} ^www.example.com\r\n\tRewriteRule (.*) http:\/\/example.com\/$1 &#x5B;R=301,L]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_domain\" style=\"padding-top:30px;\">\n<h3>Redirect old site to new site<\/h3>\n<p>When you change the domain of your site, it is recommended to redirect the traffic from the old site to the new site. Doing a 301 redirect can help you redirecting the traffic to new site without losing the search engine rankings. The following code will redirect all traffic to the current site to <code>http:\/\/newdomain.com<\/code><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule (.*) http:\/\/newdomain.com\/$1 &#x5B;R=301,L]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_dir\" style=\"padding-top:30px;\">\n<h3>Redirect all files in a directory<\/h3>\n<p>If you change a directory then you will want to redirect all files in the directory to corresponding files in the new directory.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule ^old_dir\/(.*)$ \/new_dir\/$1 &#x5B;R=301,L]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_file\" style=\"padding-top:30px;\">\n<h3>Redirect a file in a directory<\/h3>\n<p>If you have relocated just one file or only a few files in a directory to another directory, you can write a rewrite rule for each file.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule ^file.php \/new_dir\/file.php &#x5B;R=301,L]\r\n<\/pre>\n<p>You can also give absolute path if you are relocating it to a very different directory<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule ^file.php http:\/\/www.example.com\/new_dir\/file.php &#x5B;R=301,L]\r\n<\/pre>\n<p>Change http:\/\/www.example.com to your domain.<\/p>\n<\/div>\n<div id=\"change_extension\" style=\"padding-top:30px;\">\n<h3>Changing\/displaying different file extension<\/h3>\n<p>You may want to hide the actual file extension from the user and display just .html extension. e.g. The user should be able to access the page from <code>http:\/\/www.example.com\/test.html<\/code> when your actual file is test.php.<\/p>\n<p>The following .htaccess will call .php file for all .html files. However, the user will still see .html in the browser<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule ^(.+).html$ http:\/\/www.example.com\/$1.php &#x5B;NC]\r\n<\/pre>\n<p>The above code allows you to change the file extension and execute any file (e.g. php file) in the background without letting the user know about it. However, this can result in same content accessible from 2 different locations .html and .php file. It is best avoided as this causes duplicate content. So, you can just redirect all .html files to .php files. This can be done as follows:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteRule ^(.*).html$ http:\/\/www.example.com\/$1.php &#x5B;R,NC]\r\n<\/pre>\n<p>The above code will enable redirect the users to .php page. e.g. If a user is coming to <code>www.example.com\/test.html<\/code> or <code>www.example.com\/test.php<\/code> they will always be redirected to <code>www.example.com\/test.php<\/code><\/p>\n<\/div>\n<div id=\"redirect_url_string\" style=\"padding-top:30px;\">\n<h3>Redirect a URL having complete query string<\/h3>\n<p>Sometimes you would want to redirect only the URL with certain query string. The following code will redirect the page <code>index.php?query=string<\/code> to <code>\/new_dir\/index.php?query=string<\/code><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} ^query=string$ &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php &#x5B;L,R=301]\r\n<\/pre>\n<p>If you do not want to pass the query string to the new URL add &#8216;?&#8217; to the end of the new URL.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} ^query=string$ &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php? &#x5B;L,R=301]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_url_string_start\" style=\"padding-top:30px;\">\n<h3>Redirect a URL starting with specific query string<\/h3>\n<p>To redirect only URL starting a query string. The difference between the above rule and this rule is there is no &#8216;$&#8217; at the end of the Query String<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} ^query=string &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php &#x5B;L,R=301]\r\n<\/pre>\n<p>If you do not want to pass the query string to the new URL add &#8216;?&#8217; to the end of the new URL.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} ^query=string &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php? &#x5B;L,R=301]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_url_string_contained\" style=\"padding-top:30px;\">\n<h3>Redirect a URL containing specific query string<\/h3>\n<p>To redirect any URL containing a query string. The difference between the above rule and this rule is there is no &#8216;^&#8217; and &#8216;$&#8217; along with the Query String. The below code will redirect any URL containing searchword.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} searchword= &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php &#x5B;L,R=301]\r\n<\/pre>\n<p>If you do not want to pass the query string to the new URL add &#8216;?&#8217; to the end of the new URL.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{QUERY_STRING} searchword= &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php? &#x5B;L,R=301]\r\n<\/pre>\n<\/div>\n<div id=\"redirect_ipaddress\" style=\"padding-top:30px;\">\n<h3>Redirect based on ipaddress<\/h3>\n<p>Many times you would want access to some page\/directory only internally and redirect all other users to some other page. An excellent scenario of this case could be when you want to perform some maintenance on your site. During this time you have to take the site down for all external users be internally you still want to be able to access it. So we can use the following rule to allow all traffic through a particular ipaddress and redirect all other users to a maintenance page.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteCond %{REMOTE_HOST} !123.456.789.012\r\n\tRewriteCond %{REQUEST_URI} !\/maintenance.html$ &#x5B;NC]\r\n\tRewriteRule .* \/maintainence.html &#x5B;R=301,L]\r\n<\/pre>\n<p>The above rule will redirect all users not from ipaddress 123.456.789.012 and not requesting maintenance.html page to maintainence.html<\/p>\n<\/div>\n<\/div>\n<div id=\"ban_ip\" style=\"padding-top:30px;\">\n<h3>Ban visitors from specific ipaddress<\/h3>\n<p>If you want to ban visitors from certain ipaddress you can use the following rules.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\torder allow,deny\r\n\tdeny from 123.456.789.012\r\n\tdeny from 123.456.789.\r\n\tdeny from 123.456.\r\n\tdeny from 123.\r\n\tallow from all\r\n<\/pre>\n<p>In the above code the 1st line &#8220;deny from 123.456.789.012&#8221; will block the visitors from the specific ipaddress 123.456.789.012<br \/>\nThe next line blocks the visitors from all ip within the range 123.456.789.xxx (i.e. 123.456.789.000 &#8211; 123.456.789.255).<br \/>\nThe next line blocks the visitors from all ip within the range 123.456.xxx.xxx<br \/>\nThe last line blocks the visitors from all ip within the range 123.xxx.xxx.xxx<\/p>\n<p><span style=\"text-decoration:underline;\"><strong>Note<\/strong><\/span>: When you block an entire ip range as you may be accidentally blocking the legitimate visitors too. So be careful in which ipaddress or which range of ipaddress you are blocking.<\/p>\n<\/div>\n<div id=\"ban_referrers\" style=\"padding-top:30px;\">\n<h3>Ban visitors referred from certain sites<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine on\r\n\tRewriteCond %{HTTP_REFERER} baddomain.com &#x5B;NC]\r\n\tRewriteCond %{HTTP_REFERER} subdomain.baddomain.com &#x5B;NC]\r\n\tRewriteCond %{HTTP_REFERER} baddomain. &#x5B;NC]\r\n\tRewriteRule .* - &#x5B;F]\r\n<\/pre>\n<p>The above code would check the referer of the current visitor and sends a 403 Forbidden code to any visitor coming for the sites.<br \/>\nThe first line means if the referer is baddomain.com. The second line checks for subdomain.baddomain.com in the referer and the last line would check for domains baddomain.com or baddomain.net or baddomain.org or any other domain starting with baddomain.<\/p>\n<\/div>\n<div id=\"private_site\" style=\"padding-top:30px;\">\n<h3>Allow visitors only from specific ipaddress<\/h3>\n<p>If we want to allow access to our site only for certain ipaddress then we can use the following code in .htaccess file.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tOrder Deny,Allow\r\n\tDeny from all\r\n\tAllow from 123.456.789.012\r\n\tAllow from 456.789.012\r\n<\/pre>\n<p>The above code first denies access to all users and then allows access to users with ipaddress 123.456.789.012 or in the range 456.789.012.xxx<\/p>\n<\/div>\n<div id=\"disable_hotlinking\" style=\"padding-top:30px;\">\n<h3>Disable Hotlinking<\/h3>\n<p>Many sites copy content for your website and even just pull content (like images) directly from your site. This results in higher bandwidth usage for your site.<\/p>\n<p>The below code will send the hotlink.gif image is somebody tries to hotlink some images from your site.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine On\r\n\tRewriteCond %{HTTP_REFERER} !^$\r\n\tRewriteCond %{HTTP_REFERER} !^http:\/\/(www.)?example.com\/ &#x5B;NC]\r\n\tRewriteCond %{REQUEST_URI} !hotlink.gif &#x5B;NC]\r\n\tRewriteRule .*.(gif|jpg|jpeg|png|js|css)$ http:\/\/example.com\/img\/hotlink.gif &#x5B;NC]\r\n<\/pre>\n<p>The first two lines of code allows all direct users and users accessing the content through your site (http:\/\/www.example.com in this case). The third line allows access to the hotlink.gif file. The last line would send hotlink.gif instead of the actual image requested.<\/p>\n<p>The below code can be used to send a 403 Forbidden Status code when someone is accessing the hotlinked content.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteEngine on\r\n\tRewriteCond %{HTTP_REFERER} !^$\r\n\tRewriteCond %{HTTP_REFERER} !^http:\/\/(www.)?example.com\/.*$ &#x5B;NC]\r\n\tRewriteRule .*.(gif|jpg|jpeg|png|js|css)$ - &#x5B;F]\r\n<\/pre>\n<p>The above code is similar to previous one. Only difference here is that we are sending 403 Forbidden Status code instead of the hotlink.gif image.<\/p>\n<\/div>\n<div id=\"multi_domain\" style=\"padding-top:30px;\">\n<h3>Multiple domains on same file system<\/h3>\n<p>If you have just one file system sharing across multiple domains, you can easily separate the files for different domains. e.g. use directories mydomain_one, mydomain_two etc for different domains and the following .htaccess rules to redirect the users for a domain to correct files.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteCond %{HTTP_HOST} mydomain-one.com\r\n\tRewriteCond %{REQUEST_URI} !^mydomain_one\r\n\tRewriteRule ^(.*)$ mydomain_one\/$1 &#x5B;L]\r\n\r\n\tRewriteCond %{HTTP_HOST} mydomain-two.com\r\n\tRewriteCond %{REQUEST_URI} !^mydomain_two\r\n\tRewriteRule ^(.*)$ mydomain_two\/$1 &#x5B;L]\r\n<\/pre>\n<p>The above rules will direct the users for mydomain-one.com to mydomain_one and mydomain-two.com to mydomain_two directories. The above rules mean that if the requested domain is mydomain-one.com and the URL does not starts with mydomain_one, then rewrite the URL to mydomain_one directory.<\/p>\n<\/div>\n<div id=\"flags\" style=\"padding-top:30px;\">\n<h3>Some RewriteRule Flags<\/h3>\n<p>Here are some flags that we have being using in the .htaccess rules.<\/p>\n<p>RewriteRule flags are used to modify the behaviour of the rules. These flags are included in square brackets at the end of the rule. We can specify multiple flags for a rule by separating them using commas.<\/p>\n<ul>\n<li>F &#8211; Forbidden<br \/>\nThis flag results in server returning a 403 Forbidden status code.<\/li>\n<li>L &#8211; Last<br \/>\nThis flag means that if a rule is matched no further rules should be processed. Any rule after this rule will be ignored for this condition.<\/li>\n<li>NC &#8211; Nocase<br \/>\nThis flag is used when we want a case-insensitive matching. e.g. in the following code we want to match the query string searchword= irrespective whether it is in lower case or upper case or even mixed case. This rule will match &#8216;searchword=&#8217;, &#8216;SEARCHWORD=&#8217;, &#8216;SearchWord=&#8217;.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tRewriteCond %{QUERY_STRING} searchword= &#x5B;NC]\r\n\tRewriteRule index.php http:\/\/www.example.com\/new_dir\/index.php &#x5B;L,R=301]\r\n<\/pre>\n<\/li>\n<li>R &#8211; Redirect<br \/>\nThis flag is used to perform HTTP redirects. This flag can be used for any type of valid HTTP redirect using the syntax [R=301]. If no HTTP status code is provided with the flag it will used 302 status code as default.<\/li>\n<\/ul>\n<p>This is not a complete list. List of all flags can be found <a href=\"http:\/\/httpd.apache.org\/docs\/trunk\/rewrite\/flags.html\" target=\"_blank\" rel=\"external nofollow\">here<\/a>.<\/p>\n<\/div>\n<div id=\"php_variables\" style=\"padding-top:30px;\">\n<h3>Change PHP Flags<\/h3>\n<p>.htaccess file can be used to change or set new PHP flags. Example to enable magic_quotes in PHP for specific directory add the following in .htaccess inside that directory.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\tphp_flag magic_quotes_gpc on\r\n<\/pre>\n<\/div>\n<div style=\"padding-top:30px;\">\n<p><strong>Related Articles<\/strong>:<\/p>\n<ul>\n<li><a title=\".htaccess tips\" href=\"http:\/\/www.virendrachandak.com\/techtalk\/\/htaccess-tips\/\" target=\"_blank\">.htaccess tips<\/a><\/li>\n<li><a title=\"Apache Tutorial: .htaccess files\" href=\"http:\/\/httpd.apache.org\/docs\/2.0\/howto\/htaccess.html\">Apache Tutorial: .htaccess files<\/a><\/li>\n<li><a title=\".htaccess tips and tricks\" href=\"http:\/\/corz.org\/serv\/tricks\/htaccess.php\" target=\"_blank\" rel=\"external nofollow\">.htaccess tips and tricks<\/a><\/li>\n<li><a title=\"21 very useful htaccess tips &amp; tricks\" href=\"http:\/\/viralpatel.net\/blogs\/2009\/06\/21-very-useful-htaccess-tips-tricks.html\" target=\"_blank\" rel=\"external nofollow\">21 very useful htaccess tips &amp; tricks<\/a><\/li>\n<li><a title=\"Top 10 .htaccess Tips and Tricks\" href=\"http:\/\/edrackham.com\/apache\/top-10-htaccess-tips-and-tricks\/\" target=\"_blank\" rel=\"external nofollow\">Top 10 .htaccess Tips and Tricks<\/a><\/li>\n<li><a title=\".htaccess file\" href=\"http:\/\/www.htpasswdgenerator.com\/apache\/htaccess.html\" target=\"_blank\" rel=\"external nofollow\">.htaccess file<\/a><\/li>\n<li><a title=\".htaccess file\" href=\"http:\/\/perishablepress.com\/press\/tag\/htaccess\/\" target=\"_blank\" rel=\"external nofollow\">Perishable Press<\/a><\/li>\n<li><a title=\".htaccess file\" href=\"http:\/\/tools.dynamicdrive.com\/userban\/\" target=\"_blank\" rel=\"external nofollow\">.HTACCESS Banning Generator<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"padding-top:30px;\"><span style=\"text-decoration:underline;\"><strong>Note<\/strong><\/span>: I do not take responsibility for proper functioning of the above mentioned steps under all circumstances. If you download any files, programs from my blog then make sure you protect yourself. I am not responsible for any damages to your computer, website, blog, application or any thing else. I am not affiliated with or do not endorse any of the above mentioned sites.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I&#8217;ll cover more about .htaccess files. Topics Covered: Directory index file Redirection Preferred domain (www or non-www) Redirect old site to new site Redirect all files in a directory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6,8],"tags":[15,20,28,72],"class_list":["post-255","post","type-post","status-publish","format-standard","hentry","category-server-configuration","category-web-development","tag-htaccess","tag-apache","tag-configuration-file","tag-url-redirection"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>more .htaccess tips - Virendra&#039;s TechTalk<\/title>\n<meta name=\"description\" content=\"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I&#039;ll cover more about\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"more .htaccess tips - Virendra&#039;s TechTalk\" \/>\n<meta property=\"og:description\" content=\"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I&#039;ll cover more about\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\" \/>\n<meta property=\"og:site_name\" content=\"Virendra&#039;s TechTalk\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:published_time\" content=\"2011-10-17T05:08:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-02-21T00:37:06+00:00\" \/>\n<meta name=\"author\" content=\"Virendra Chandak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:site\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virendra Chandak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\"},\"author\":{\"name\":\"Virendra Chandak\",\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17\"},\"headline\":\"more .htaccess tips\",\"datePublished\":\"2011-10-17T05:08:04+00:00\",\"dateModified\":\"2015-02-21T00:37:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\"},\"wordCount\":2289,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17\"},\"keywords\":[\".htaccess\",\"Apache\",\"Configuration file\",\"URL redirection\"],\"articleSection\":[\"Server Configuration\",\"Web Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\",\"url\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\",\"name\":\"more .htaccess tips - Virendra&#039;s TechTalk\",\"isPartOf\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#website\"},\"datePublished\":\"2011-10-17T05:08:04+00:00\",\"dateModified\":\"2015-02-21T00:37:06+00:00\",\"description\":\"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I'll cover more about\",\"breadcrumb\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"TechTalk\",\"item\":\"https:\/\/www.virendrachandak.com\/techtalk\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Server Configuration\",\"item\":\"https:\/\/www.virendrachandak.com\/techtalk\/category\/server-configuration\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"more .htaccess tips\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#website\",\"url\":\"https:\/\/www.virendrachandak.com\/techtalk\/\",\"name\":\"Virendra's TechTalk\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.virendrachandak.com\/techtalk\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17\",\"name\":\"Virendra Chandak\",\"logo\":{\"@id\":\"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.virendrachandak.com\",\"https:\/\/www.facebook.com\/virendrachandak\",\"https:\/\/www.linkedin.com\/in\/virendrachandak\/\",\"https:\/\/x.com\/virendrachandak\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"more .htaccess tips - Virendra&#039;s TechTalk","description":"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I'll cover more about","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/","og_locale":"en_US","og_type":"article","og_title":"more .htaccess tips - Virendra&#039;s TechTalk","og_description":"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I'll cover more about","og_url":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/","og_site_name":"Virendra&#039;s TechTalk","article_publisher":"https:\/\/www.facebook.com\/virendrachandak","article_author":"https:\/\/www.facebook.com\/virendrachandak","article_published_time":"2011-10-17T05:08:04+00:00","article_modified_time":"2015-02-21T00:37:06+00:00","author":"Virendra Chandak","twitter_card":"summary_large_image","twitter_creator":"@virendrachandak","twitter_site":"@virendrachandak","twitter_misc":{"Written by":"Virendra Chandak","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#article","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/"},"author":{"name":"Virendra Chandak","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"headline":"more .htaccess tips","datePublished":"2011-10-17T05:08:04+00:00","dateModified":"2015-02-21T00:37:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/"},"wordCount":2289,"commentCount":3,"publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"keywords":[".htaccess","Apache","Configuration file","URL redirection"],"articleSection":["Server Configuration","Web Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/","url":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/","name":"more .htaccess tips - Virendra&#039;s TechTalk","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website"},"datePublished":"2011-10-17T05:08:04+00:00","dateModified":"2015-02-21T00:37:06+00:00","description":"In my previous post .htaccess tips I had started with what is .htaccess file and some things that can be done using it. In this post I'll cover more about","breadcrumb":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.virendrachandak.com\/techtalk\/more-htaccess-tips\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"TechTalk","item":"https:\/\/www.virendrachandak.com\/techtalk\/"},{"@type":"ListItem","position":2,"name":"Server Configuration","item":"https:\/\/www.virendrachandak.com\/techtalk\/category\/server-configuration\/"},{"@type":"ListItem","position":3,"name":"more .htaccess tips"}]},{"@type":"WebSite","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website","url":"https:\/\/www.virendrachandak.com\/techtalk\/","name":"Virendra's TechTalk","description":"","publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.virendrachandak.com\/techtalk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17","name":"Virendra Chandak","logo":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.virendrachandak.com","https:\/\/www.facebook.com\/virendrachandak","https:\/\/www.linkedin.com\/in\/virendrachandak\/","https:\/\/x.com\/virendrachandak"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2vTtQ-47","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":0,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}