views:

41

answers:

1

I want to cahange mysite.com/profile.php into mysite.com/profile

I wrote the htacess file as

RewriteEngine On 

RewriteRule ^profile/?$ profile.php [NC,L]

and placed in root directory. It doesn't work. I use the apache server. What is wrong with my program?

+3  A: 

Try something like this instead:

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

That way you dont have to do it for each individual URL.

credit

Mark
I need some more explanation.because I am newbie to URL rewriting.What does !-d and -f indicates
vinothkumar
!-d means "if it's not a directory"-f means "if it's a regular file"So... if the requested filename isn't a directory, but the same path with .php is appended, send the PHP file.
Michael Johnson
BTW, got that from http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html as the official reference docs. You should also check out http://httpd.apache.org/docs/2.2/rewrite/ for more rewrite-foo.
Michael Johnson
You don’t need to escape the dot in `%{REQUEST_FILENAME}.php` since that’s not a regular expression.
Gumbo