WP 301 Redirect on my 404.php error page

4 replies
Hey all read a lot here but don't post much.

OK I'm looking to add this code in my 404.php error page in WordPress.



<?php
header("Status: 301 Moved Permanently");
header("Location:h-t-t-p://w-w-w.domain.com");
?>

NOte: the dashes in the code above are only there because I can not post links in the forum.


This will give me a nice 301 redirect.

I wanted to add the WP home page URL code in place of the domain.com.

my issue is I not sure what the WP code is for grabbing the home site domain URL.


Hope this makes sense.

Thanks

Chad
#301 #404php #error #page #redirect
  • Profile picture of the author Istvan Horvath
    Actually, it doesn't (make sense).

    Where is your WP installed? In a subfolder? Then that is the URL of your WP blog.
    Say, you have example.com (btw, ALWAYS use "example.com" for examples... that domain is reserved for that by ICANN) and your blog is at example.com/blog <== that's what you put in the redirect.
    Signature

    {{ DiscussionBoard.errors[3163831].message }}
  • Profile picture of the author ChadCook
    No... I know what my domain name is and what to add for the URL to redirect.


    What I want is the WordPress code to call the root domain rather than just adding the domain name.

    Why...because I have a number of sites with edited themes and if I can have this auto set with the domain name for the root domain of the blog then I will not have to edit this file every site I build.
    {{ DiscussionBoard.errors[3163940].message }}
    • Profile picture of the author Istvan Horvath
      Originally Posted by ChadCook View Post

      Why...because I have a number of sites with edit themes and if I can have this auto set the domain name for the root domain of the blog then I will not have to edit this file every site I build.
      Sorry, I thought I knew WP... but I still don't get your question

      What is "root domain"? Never heard of it.

      What do themes have to do with PHP redirects?

      Describe exactly what do you want to do; what is your goal; what do you want to achieve?

      To have a 404.php template file in your theme(s) to redirect to the URL of the WP install?

      Did you try the Codex? The WP online manual?
      (nobody wants to read)
      Function Reference/bloginfo « WordPress Codex
      Signature

      {{ DiscussionBoard.errors[3163979].message }}
  • Profile picture of the author crystalq
    This code works amazingly well! However, does anyone know how to redirect the track backs??? Its redirecting all of my old posts & random urls that people type in but its not redirecting my old track backs.

    Would I make a .htacess file for that or can I add something to this code?? Any help would be much appreciated
    {{ DiscussionBoard.errors[4467993].message }}

Trending Topics