Dylan Taylor
Dylan Taylor

Reputation: 351

How can I remove the .php extension using .htaccess rules?

I need for my .htaccess file to take away the .php file extension and replace it with just a trailing slash.

Also, I have a profile.php page which will normally be visited with a numeric querystring parameter, like "profile.php?id=3".

So on top of replacing extensions with slashes, how do I make "profile.php?id=3" look like "profile/3/"?

So far all I have is the first line:

RewriteEngine on

Where do I go from here?

Upvotes: 0

Views: 474

Answers (2)

Lombo
Lombo

Reputation: 12235

This should do it

RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L]

Upvotes: 0

Frankie
Frankie

Reputation: 25165

If you're so new... you really should read the manual.

// if not a file
RewriteCond %{SCRIPT_FILENAME} !-f
// if not a directory
RewriteCond %{SCRIPT_FILENAME} !-d
// pass all params back to index.php
// QSA stands for query string append
// L stands for last rule
RewriteRule (.*) index.php?$1 [QSA,L]

But this will do what you want. Now don't be lazy. Read the manual!

Upvotes: 4

Related Questions