简体   繁体   中英

Rewrite URL with parameters passed through PHP

So I have my PHP page page.php with the parameter id for example.

Everything works as expected when I visit

page.php?id=1

What I try to do now basically is, reach the site when the user visits

page/1

I've looked at countless questions and websites about htaccess rewrites and so on, but I'm not even entirely sure if I need that. I did the exact same thing in an old project of mine where I can't find any htaccess file, but I also have no idea what I really did.

And in case I do need the htaccess file. How do I ensure that it works properly?

Alright, gotta put this in the htaccess

RewriteEngine On
RewriteRule ^page/([^/]*)$ /page.php?id=$1 [QSA,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