Redirect using regular expression and possible post meta lookup
-
Hi,
I have a situation where an old site has vanity URLs to individual detail pages with the following format:
Where “/12345” is a unique ID of the post for the post detail page. Think of this like a vanity URL to go right to a property detail page.
The redirection needs to parse the regular expression of digits after the last slash only, and do one of two things:
Option 1 (preferred): Parse URL digits and do a lookup using those digits to find the post using the digits from the URL in a post_meta query. The post slug is the post name (different than the digits), but those digits are in the post_meta:
/12345 -> regular expression to get digits from URL -> use a WordPress function to do a query to find the post having “12345” as post_meta -> redirect to post using normal permalink
Option 2: Do a regular expression to parse the digits and redirect to a search query:
/12345 -> redirect to /listings/?keyword=id-12345
Option 1 is preferred to have vanity URLs that are short with the post_meta ID, but keep the true permalink the post title for SEO reasons.
Any help is greatly appreciated!
Thanks in advance,
Kevin
- The topic ‘Redirect using regular expression and possible post meta lookup’ is closed to new replies.