1

I have an .htaccess file:

In this file it redirects to index.php in case a file or directory is not found.

My code is as below:

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Everything is working fine with this code. Now when I get Forbidden error(403), I would like it to be redirect to index.php.

Do you have an idea how to write an .htaccess file for this purpose?

2

You want to use the ErrorDocument rule. Using your example, it might look something like this:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^(.*)$ index.php?/$1 [L]    
</IfModule>    
ErrorDocument 403 index.php
  • Thanks for your answer you great bro... your answer was not exact but found the way...thanks again – Jitesh Tukadiya Apr 12 '13 at 5:02

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.