title: how many htaccess files there shall be?
body: <p>How i shall organise htaccess files?
  Shall there be a single file, or file in each folder?
  I have somedomain/public/.htaccess, which puts url string to <code>$_REQUEST['url']</code> variable. This is the second part of the code below, and it works.</p>
  
  <p>Later, i created somedomain/.htaccess with code for redirecting to <a href="https://www" rel="nofollow noreferrer">https://www</a>.<br>
  Two separate files did not work, thus i pasted the somedomain/public/.htaccess to somedomain/.htaccess. But nothing works. How to achieve these two functionalities. I means redirection to <a href="https://www" rel="nofollow noreferrer">https://www</a> and url fetching to variable. Where is the mistake below?</p>
  
  <p>Shall i create somedomain/.htaccess,  somedomain/public/.htaccess,  somedomain/somefolder/.htaccess, ....</p>
  
  <p>Or i shall have only one somedomain/.htaccess which deals with all redirections?
  If i have only one somedomain/.htaccess as it is below, how i shall redirect 
  <code>somedomain</code> to <code>somedomain/public/index.php</code>
  <code>somedomain/{url not matching somedomain/public/index.php/parameters}</code> to <code>error</code></p>
  
  <p>folder structure</p>
  
  <pre><code>somedomain.com/
        .htaccess
        /public
              #.htaccess #the second part of code, which i copied to somedomain.com/.htaccess
              index.php
  </code></pre>
  
  <p>.htaccess in somedomain.com/</p>
  
  <pre><code>#first part of htaccess
  # Rewrite to HTTPS:
  # If www. is already there it will be included, if not
  # it will be catched by the subsequent rule.
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
  #[L,R=301]
  
  # Now, rewrite any request to the wrong domain to use www.
  # [NC] is a case-insensitive match
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} 
  #[L,R=301]
  
  RewriteEngine On
  # the default webpage loaded by the server:
  DirectoryIndex /public/index.php/security/login
  IndexIgnore * 
  
  #Second part of htaccess
  #rules to fetch controller name and method name starting from /public/index.php/
  RewriteBase /public/
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{ENV:REQUEST_FILENAME} !-d
  RewriteCond %{ENV:REQUEST_FILENAME} !-f
  RewriteCond %{ENV:REQUEST_FILENAME} !-l
  
  RewriteRule ^index.php?(.+)$ index.php?url=$1 [QSA,L] 
  </code></pre>
  
  <p>I am gettting the error : The server encountered an internal error or misconfiguration and was unable to complete your request. ...
  Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
  
  <p>Previously i had only the second part of .htaccess in somedomain.com/public .</p>
  
  <p>Server error logs:</p>
  
  <pre><code>[Thu Apr 20 08:37:36 2017] [error] [client 213.133.81.6] File does not exist: /home/gintare/public_html/typejoy.biz/500.shtml
  [Thu Apr 20 08:45:43 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 08:45:43 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 08:46:04 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 08:46:04 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 08:46:08 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 08:46:08 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
  [Thu Apr 20 10:05:04 2017] [warn] RSA server certificate CommonName (CN) `typejoy.biz' does NOT match server name!?
  [Thu Apr 20 10:50:27 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/favicon.ico
  [Thu Apr 20 10:50:27 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/404.shtml
  [Thu Apr 20 10:51:41 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/favicon.ico
  [Thu Apr 20 10:51:41 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/404.shtml
  </code></pre>