Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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. –  amod0017 Nov 1 '12 at 6:26

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(); ?>`
share|improve this answer
    
thnx Simon let me just try it buddy... :) –  amod0017 Oct 31 '12 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? –  amod0017 Oct 31 '12 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 '12 at 9:59
    
Thnx Simon for your valuable comment. I learned a new thing... :) –  amod0017 Nov 1 '12 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.