Showing posts with label .htaccess. Show all posts
Showing posts with label .htaccess. Show all posts

Saturday 14 September 2019

After installed Magento 2, got Internal server error due to IfVersion < 2.4

Following .htaccess code is not working in Magento 2

<Files composer.json>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>

Ans.  Just enabled "mod_version" from your server

Thursday 11 October 2018

How to redirect www to non www AND http to https in AWS .htaccess


AWS WWW to non WWW redirection
RewriteEngine On
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
AWS HTTP to HTTPS redirection
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
AWS WWW to non WWW and HTTP to HTTPS
RewriteEngine On
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^.*$ https://example.com%{REQUEST_URI}
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://example.com%{REQUEST_URI}

Tuesday 29 May 2018

How to force redirect HTTP to HTTPS in AWS or any other server using .htaccess

1st Method
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

2nd Method
<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{HTTPS} !on
     RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Friday 6 November 2015

Disable mod_rewrite for subdirectory OR Set Apache Password Protected Directories With .htaccess File OR API Protected


If you don't know the username and password to enter, then you can't access the page or site - it's "password protected". It's sometimes handy to be able to password protect your pages like this - for example:


  1. You're building a new site, but you only want yourself (and maybe a select few) to be able to view the work-in-progress.
  2. You have an area of your site that you never want the general public to have access to - for example, your web stats or private pages.
  3. You have some paid (subscription) content on your site that only subscribers should be able to access.
  4. Apache lets you password protect individual files, folders, or your entire site fairly easily. Read on to find out how it's done.


  1. Create a special file called .htaccess in the folder you want to protect.
ErrorDocument 401 "Unauthorized"
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/*/public_html/directory/.htpasswd
require user myusername_same_as_.htpasswd_file
     2. Creating the password file Called .htpasswd
The first step is to create a simple text file that will store your username and password, separated by a colon (:). The small catch is that the password must be encrypted. Luckily, there are many free web-based utilities that will encrypt the password for you. Try one of these:
myusername_same_as_.htaccess_file:$apr1$TSQAiMQm$MIJ.m3qpJ3mnY6NXdzppz. 

Thursday 10 September 2015

Enable gzip compression

What is gzip Compression?

When a user visit your website a request is made to web server to deliver the requested data. The response of the server is directly proportional to the size in mb/kb of the page as generally all pages contains video, images and textual part. so as page size bigger response time will be higher
Gzip facilitate to compress the your webpages  video, image and textual and style sheets before serving the request them over to the browser. This really reduces response time since the files are now in less size due to compression.
Gzip is the technique right now most effecting in the all speed optimization concept

How Apply Gzip to Apache Server Website

First of all you need to have a “.htaccess” file, If not create it and edit with the following code.

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>


After Applying the code to the htaccess test the website url with a http://checkgzipcompression.com/.

Thursday 27 August 2015

Redirect all urls exactly, just change domain name

How to change domain using htaccess file

Many times we have a in CMS and Ecommerce website to change the domain due to maintenance or other reason but the main headache is the suburl (categories or collection) should be work as it is other wise we need to write the 301 url redirect for each and every url to not get the SEO errors.
This is tutorial will be help for the following CMS :
  1. wordpress development
  2. Joomal development
  3. Drupal development
There are Ecommerce platform that get help from this
  1. Magento development
  2. Opencart development
  3. Woocommerce
  4. Virtumart
So here is the simple and easy option that will work using the add the few lines in the htaccess file (if file not available create it .htaccess).


RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]