1

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.

2 Answers 2

3

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.

1
  • Exactly what I wanted. Thnx... Accepting the answer. You told it in a UI way which matters a lot as I dont know much about wordpress coding.
    – amod
    Nov 1, 2012 at 6:26
1

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 :

<?php
/* 
* Template Name: Redirect
* 
*/

wp_redirect( 'mypage.example.com', 301 );

?>

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).

<?php get_header(); ?>

<script type="text/javascript">
<!--
  window.location= <?php echo "'" . home_url() . "'"; ?>;
//-->
</script>

<?php get_footer(); ?>`
4
  • thnx Simon let me just try it buddy... :)
    – amod
    Oct 31, 2012 at 18:49
  • hi Simon... using the Yoast Plugin is great option but its redirecting it to "example.com/mypage/subdomain.com" I am sure I am entering something wrong. Any pointer on this?
    – amod
    Oct 31, 2012 at 19:02
  • 1
    Mike's solution is best solution. For Yoast Plugin, you need to enter full URL like http://example.domain.com
    – Simon
    Nov 1, 2012 at 9:59
  • Thnx Simon for your valuable comment. I learned a new thing... :)
    – amod
    Nov 1, 2012 at 16:56

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .