user1899812
user1899812

Reputation:

Changing Request URL by the Server

A sample URL of a question posted on StackOverflow is given below.

http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array

The above URL is the complete URL to a question on StackOverflow, but you can also load the same page using the URL below (note that the description at the end is deleted):

http://stackoverflow.com/questions/11227809

Try loading the above URL and after the page loads, look at the address bar, it would look like the URL mentioned at first.

I think what happens when requesting with the 2nd URL is this:

  1. StackOverflow searches and finds a question with id 11227809.

  2. Then it redirects the user back to the original URL.

Are my assumptions correct? How can I do something like this with PHP? (just some background of how-to, and I know that stackoverflow is written in asp.net)

Upvotes: 0

Views: 962

Answers (1)

fejese
fejese

Reputation: 4628

You can store slugs for contents with ids. If you look at $_SERVER you'll find the requested url. So if it does not contain the slug then you can look it up in the db and redirect to it.

Upvotes: 1

Related Questions