views:

55

answers:

2

hello i am trying to make it so that when you visit my site you don't have to put .php at the end this is what i am using but it isn't working (godaddy hosting)

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

i just added the "Options +FollowSymlinks" today and it still didn't work. Thanks a lot

A: 

I'd say that

RewriteCond %{REQUEST_FILENAME}\.php -f

is unnecessary. What shall that be for?

cweiske
i don't know i just googled it
Matthew Carter
This will avoid infinite recursion as only requests get rewritten that can positively mapped onto an existing `.php` file.
Gumbo
is something wrong because it gives me a 404
Matthew Carter
in no way it is unnecessary! it prevents something like test.html of being rewritten to test.html.php!!
ITroubs
A: 

i don't know yet what the "FollowSymLinks" does but the rest does that:

RewriteEngine On            <-- activates mod rewrite
RewriteCond %{REQUEST_FILENAME} !-d  <-- condition that says: request filename is not directory
RewriteCond %{REQUEST_FILENAME}\.php -f  <-- condition that says: request filename with the appendix .php is a file
RewriteRule ^(.*)$ $1.php  <-- take anything you get and put a .php behind it

to tell it in human words: if the requested filename is not a directory and if you append .php to that filename and it is an existing file then do the rewrite rule which appends .php to the requested file

this works on my XAMPP:

<IfModule mod_rewrite.c>
    RewriteEngine On            
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>
ITroubs