Andrei Stanca Andrei Stanca - 3 months ago 19
Apache Configuration Question

godaddy .htaccess RewriteRule

I'm trying to set up a .htacess file on Godaddy webhosting ( apache-linux ofcourse, not IIS ). But i`m stuck with a problem:

RewriteEngine On
Options +FollowSymLinks
Rewriterule ^templates/.*$ - [PT]
Rewriterule ^controllers/.*$ - [PT]
Rewriterule ^.*$ index.php [NC,L]


I`m getting an Internal Server Error for line:


Rewriterule ^.*$ index.php [NC,L]


I don't know how to fix this, i've tried everything I know... basically I want to send anything that comes to index.php where a bootstrapper is set. This is working on any hosting i`ve ever tried, but godaddy seems to have problems with this: ^.*$ any help would be appreciated.

Answer

This rule

Rewriterule ^.*$ index.php [NC,L]

looks OK, but make sure that there are no spaces between the flags i.e [NC, L] should be changed to [NC,L].

You can try the equivalent to see if it makes a difference (you don't need NC because it already matches any request)

Rewriterule .* index.php [L]

If that is not the issue, then it is likely the rules before that cause it to fail. Comment them both out and see if it works, but add a RewriteCond as below

Options +FollowSymLinks
RewriteEngine On

#if its not already index.php
RewriteCond %{REQUEST_URI}  !index\.php$ [NC]
Rewriterule .* index.php [L]

If those rules are the real cause, then I would like to know what was your intent with those rules, and can they be expressed a different way i.e. if the intent was to rewrite all content except that in the templates or controllers directory, then that could be achieved by

#if request is not for templates or controllers directory
RewriteCond %{REQUEST_URI}  !^/(templates|controllers)/ [NC]
Rewriterule .* index.php [L]
Comments