views:

43

answers:

3

I'm using a couple of rewrite directives that always works before on apache2 but now trying a new shared hosting and the rewrite rules do not seem to get applied.

I've reduced the .htaccess files to the following essential rules:

RewriteEngine On
Rewritebase /demo/

RewriteRule ^(.*)$ index.php/$1 [L]

As you can see, i want to rewrite every request to my index.php file in the demo folder from root.

So everything like http://www.example.com/demo/albums/show/1 should be processed by http://www.example.com/demo/index.php for a standard MVC setup. (I'm using CodeIgniter btw)

The directives above results in a 500 error, so i thought maybe because of some possible syntax differences between 1.3 and 2.x.

After some trail and error editing, i've found the rewrite rule itself to be at fault but i really don't understand why.

  • Any ideas to why my rewrite rule doesn't work? it did before on lots of different servers.
  • Suggestions how to fix it?

Note: mod_rewrite does work, i've written a small test to be sure.

+1  A: 

In your position, I'd probably look in the Apache error log first, then would try to eliminate one moving part by doing

RewriteEngine On
RewriteRule ^/demo/index.php$ /demo/index.php [L]
RewriteRule ^/demo/(.*)$ /demo/index.php/$1 [L]

If that worked, I'd try reintroducing RewriteBase.

Dave W. Smith
Thanks, good tip, i've removed the RewriteBase directive and this results in a 200 response for the root .../demo/ , but any other results in a plain old 404 from apache (not handled by my script as i can tell from my logs).
Sander Versluys
I added a RewriteRule above to avoid an accidental rewrite. There's a way to do that with a RewriteCond, but that'd require coffee.
Dave W. Smith
+1  A: 

Did you set:

Options +FollowSymLinks

… before the rewrite rules? If FollowSymLinks is disabled mod_rewrite won’t work.

toscho
good tip, but adding it doesn't seem to help... txn ;-)
Sander Versluys
+1  A: 

It may be that you’re running into an infinite recursion since index.php/… is also matched by ^(.*)$. So try to exclude your target:

RewriteCond $1 !^index\.php/
RewriteRule ^(.*)$ index.php/$1 [L]
Gumbo
Agreed - it's a bad pattern