How was a URL like http://stackoverflow.com/posts/1807421/edit created in PHP?

后端 未结 8 1021
暖寄归人
暖寄归人 2021-01-23 06:10

When you edit a question on stackoverflow.com, you will be redirected to a URL like this:

https://stackoverflow.com/posts/1807421/edit

8条回答
  •  感动是毒
    2021-01-23 07:08

    It's indeed done by mod_rewrite, or with multiviews. But i prefer mod_rewrite.

    First: you create a .htaccessfile with these contents:

    RewriteEngine On
    RewriteRule ^posts/([0-9])/(edit|delete)$ /index.php?page=posts&postId=$1&action=$2
    

    Obvious, mod_rewrite must be enabled by your hostingprovider ;)

提交回复
热议问题