I have the following content in my .htaccess file. I expected it to redirect to my project folder /hc which is at the same level as .htaccess. The redirection is not happening and it is still displaying the contents of index.html.

RewriteEngine On

RewriteBase /hc/

<Files .*>
    Order Deny,Allow
    Deny From All

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L,QSA]

2 Answers 2


I expected it to redirect to my project folder /hc which is at the same level as .htaccess.

That's the problem. If the .htaccess file is in the /hc subdirectory then it's never going to see the request unless you already include the /hc subdirectory on the request.

Your .htaccess file needs to go in the parent directory. ie. the document root. (Incidentally, you would only need the RewriteBase /hc/ directive if this file was in the document root.)

Or, include an additional .htaccess file in the document root that simply forwards all requests to your /hc directory (your front controller), for example:

RewriteEngine On
RewriteRule (.*) hc/$1 [L]

Note that since mod_rewrite is not inherited by default, once the request is rewritten to the /hc subdirectory, the .htaccess file in the subdirectory is then processed and overrides the mod_rewrite directives in the parent .htaccess file, so you don't end up with a rewrite loop.

RewriteRule .* index.php?/$0 [PT,L,QSA]

UPDATE: Your substitution string in the last RewriteRule differs from the earlier directive. Both are probably not correct. You may want to remove the ? in the above directive, unless you intend to us the query string, then you should add a ? to the earlier directive. As it stands, the first uses path information to pass the URL, the second uses the query string.

Incidentally, the PT flag is redundant in per-directory .htaccess files. And if you aren't using the query string, then the QSA flag can be removed also.

  • I have put the .htaccess in my parent (public_html) still no success.
    – logeeks
    Jan 17, 2017 at 15:48

You need to let "rewrite" option in your "sites-available" apache config file. For laravel you should be careful because your DocumentRoot (public folder where you need .htaccess file) is inside project folder .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.