Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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. :|

share|improve this question

closed as off topic by EEAA, Ward, mdpc, Scott Pack, John Gardeniers Dec 4 '12 at 5:43

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

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

1 Answer

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.

share|improve this answer
    
Thanks but it's still not working. No errors, either. –  SFault Dec 2 '12 at 21:29
    
@SFault, okay, I've updated the answer with more info. –  rightstuff Dec 2 '12 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 '12 at 21:37
    
index.php gets opened and there's nothing in the error logs. –  SFault Dec 2 '12 at 23:10
    
@SFault, "index.php gets opened"... That sounds like the above rules work then? –  rightstuff Dec 3 '12 at 14:39
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.