I just came across this page with almost similar requirements as mine
Multiple endpoints to same page
i have to achieve same functionality but i also want to pass some parameters to the page where all these URL will be map.
say example
http://mysite.com/test/link1 http://mysite.com/test/link2 http://mysite.com/test/link3
i want to map them to same URL
http://mysite.com/test/finalDestination
along with it i also want to send some other parameters like
- user email
- user name
so that i can use them at that page for my custom logic.i know how to do it in JSP/Java where i can send them as a request parameters in POST request and can reterieve them in the final JSP
how i can achieve this is wordpress using php.my prefrences are not to use any query string.
Or is it possible like if i create URL with like
http://mysite.com/test/user1 http://mysite.com/test/user2 http://mysite.com/test/user3
where user1 etc can be fetched from the database and we can ensure that they will be unique through the application and mapping these URLs to same end point.
how can i fetch the username in my final page?
Thanks in advance
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can use the same answer as the question you referred to (I have answered it). Here’s how you would change to pass the arguments:
<?php
add_action('init', 'add_my_rule');
function add_my_rule()
{
global $wp;
$wp->add_query_var('args');
add_rewrite_rule('test/finaldestination/(.*)','index.php?pagename=about&args=$matches[1]','top');
}
?>
Assuming ‘finaldestination’ stays the same always, and the pagename (slug) is ‘about’ (you can change both). Apply your custom template to this page, and on the template, do this:
//if you visit http://.../test/finaldestination/name/romeo, then $params will be name/romeo. You can explode this and get the value.
$params = get_query_var('args');
After you put this code in your file, just go to Settings>Permalinks and hit the save button.
I haven’t tried this, but have used something similar in a recent project and I’m sure it will work.
Method 2
Just be sure to add a canonical URL into the header of the duplicate pages, referring to the main instance of the page … else you’ll end up with duplicate content – which is bad for SEO (only matters if these pages are public and indexed).
Also would go for the theme’s author.php or permalink %author% in case it’s regular WordPress users. You can access the data about like that:
$author = get_user_by('slug', $author_name);
$author_id = (int)$author->ID;
$name = $author->first_name.' '.$author->last_name;
Method 3
If your words made senses to me correctly, possible solutions are here:
For the first part, you may use WordPress Redirection plugin to satisfy your needs easily.
For the second part, you may use %author% for permalink structures. Check out codex.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0