简体   繁体   中英

PHP prevent changing url slug

I noticed that some sites prevent modification of the slug in the URL. For exemple in stackoverflow if you change the slug of this post, when you load the page, the real slug comes back.

This is not Javascript, so I supposed it is managed by PHP. I do not see how to do it and I really can not find any answer on the web... Anyone know ?

As MattWritesCode notes in the comment, the important part is ID. What you can do is load the canonical slug from the database by using the ID, and if the user-provided slug does not match what you have in the database, do a redirect to the canonical ID+slug URL.

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