简体   繁体   中英

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?

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!

这应该做

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM