-3

I have this following in my .htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteRule  (.*)\.php$ index.php

I just want to rewrite every .php file accessed to index.php, changing everything after the first slash. I wonder why it isn't working. Been stuck in this for hours now. :|

2
  • Have you verified that you are allowed to set these options in your .htaccess file? See the Apache manual
    – voretaq7
    Dec 3, 2012 at 3:18
  • ^Yes. In fact, I wrote a different rule earlier on the same .htaccess file and it worked.
    – sfault
    Dec 3, 2012 at 8:35

1 Answer 1

1

Try...

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

This will use index.php as the internal script for the request (with the original relative url appended as a query string to index.php), it will not redirect to index.php.

Also make sure that you have the proper options and allowoverride set for this directory to be able to use rewriterules.. Which includes needing FollowSymlinks.

Test with -

Options All
AllowOverride All

...in httpd.conf or where the Directory is defined. Restart Apache.

Make sure that mod_rewrite is loaded.

And also check Apache's error log.

5
  • Thanks but it's still not working. No errors, either.
    – sfault
    Dec 2, 2012 at 21:29
  • @SFault, okay, I've updated the answer with more info.
    – rightstuff
    Dec 2, 2012 at 21:34
  • @SFault, place <?php echo "Hello World"; ?> at the top of index.php to test if it's not getting to this file.
    – rightstuff
    Dec 2, 2012 at 21:37
  • index.php gets opened and there's nothing in the error logs.
    – sfault
    Dec 2, 2012 at 23:10
  • @SFault, "index.php gets opened"... That sounds like the above rules work then?
    – rightstuff
    Dec 3, 2012 at 14:39

Not the answer you're looking for? Browse other questions tagged .