如果部分网址或短网址出现,如何重定向原始网址

I want to redirect url if partial url get like stackoverflow manage or other sites. Is that possible in php.

eg. https://stackoverflow.com/questions/21150608/htaccess-redirect-partial

It automatic convert to orignal url

eg. https://stackoverflow.com/questions/21150608/htaccess-redirect-partial-url-pattern

You can do that by using .htacess

# Permanent URL redirect 
Redirect 301 /questions/21150608/htaccess-redirect-partial /questions/21150608/htaccess-redirect-partial-url-pattern

The important part of the url is the id, e.g.

yourdomain.com/questions/{id}/{slug}

You would have to check the id against a database and check if the slug provided matches the slug related to the requested id, if not, redirect to the complete url.