1

I'm setting up a php mvc framework and I want to redirect anything after the domain to index.php/$1 but it's not working. I have rewrite_module enabled and AllowOverride All, is there something else I'm missing?

Basically I want the url to go from this http://www.example.com/foo/bar to http://www.example.com/index.php/foo/bar so I can grab it from $_SERVER['PATH_INFO']

Here's what I have...

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot c:/wamp/www
  ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:/websites/snugglemvc"
    ServerName www.snugglemvc.com
    <Directory "c:/websites/snugglemvc">
        Order Deny,Allow
        Allow from all
        AllowOverride all
    </Directory>
</VirtualHost>
bflemi3
  • 6,698
  • 20
  • 88
  • 155

2 Answers2

1

I believe you need the leading slash on /index.php as your regex matches beginning of line.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
Mark
  • 768
  • 5
  • 12
  • @bflemi The rule is fine and working great. If it does not work for you then what do you get, an error? Try putting `[R=302,L]` temporarily to see if rule is actually working (redirect occurs). – LazyOne Jul 06 '11 at 09:38
  • @LazyOne Thanks, I'll try it when I get home and let you know. When I go to www.example.com/foo/bar i get a 404, but when i go to www.example.com/index.php/foo/bar then it works fine. I guess thats because at that point the rewrite is not needed and PATH_INFO is set. – bflemi3 Jul 06 '11 at 13:55
  • @LazyOne Nope, that's not working either. I don't think mod_rewrite is working. – bflemi3 Jul 06 '11 at 21:49
  • @LazyOne Sorry, should have been more specific, it's on my local. I'll edit the above post with my httpd-vhosts. Also, if i add an illegal command to the .htaccess, like 'hello' for instance, it doesn't throw a 500. – bflemi3 Jul 06 '11 at 22:14
  • @LazyOne Also, the above .htaccess is the full file. I've gotten rid of everything for now just to troubleshoot. Thanks for all your help by the way! – bflemi3 Jul 06 '11 at 22:18
  • @LazyOne 1) google redirect didn't work, 2) yes that line is uncommented. – bflemi3 Jul 06 '11 at 22:23
  • @LazyOne 3)didn't work either. One thing to mention... I originally had wamp 64 bit installed but uninstalled it to install 32 bit as mongodb wasn't compatible with 64bit. Could that have anything to do with it? – bflemi3 Jul 06 '11 at 22:26
  • @LazyOne let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1199/discussion-between-bflemi3-and-lazyone) – bflemi3 Jul 06 '11 at 22:26
0

it was an issue with my httpd.conf file. i didn't have AllowOverride all on the localhost. once I changed that everything worked.

bflemi3
  • 6,698
  • 20
  • 88
  • 155