I have a blog on wordpress say example.com with a page name “mypage” in it. When a user clicks on mypage I want him to redirect to mypage.example.com (a subdomain that I have already created) inspite of opening example.com/mypage. I want my page to redirect to my subdomain.
I am a user of wordpress and hence I dont know much about how to do it. Please help me out on it, I would be really thankfull.
Leave a Reply
You must be logged in to post a comment.
Can you use a custom menu (Appearance -> Menus) ? If so, just create a custom link and insert it where desired. This has the added benefit of not cluttering your list of pages with a page that isn’t real.
I would say you have two options :
1/ You could use a Plugin like Yoast SEO, which is useful to SEO and allow you to define a 301 redirection to any page (just install the plugin, go to the page you need to redirect, and in the SEO options, in Advanced, you will find a redirect field where you could enter the URL where you want to redirect
or 2/ Create new file redirect.php with this code that you place in your theme folder via FTP :
Then change the template of your example page to this Redirect template, which will redirect to the subdomain with a 301 redirection.
* EDIT *
This is a wrong answer. You cannot use wp_redirect() because http headers are already processed at this point. I used successfully this code that rely on Javascript to redirect the page (not a perfect solution if JS is desactivated, of course).