Support » Developing with WordPress » Pass external url trough if page not found

  • Hello,

    Is it possible to pass a external content form other domain if a 404 happens?
    We installed a wordpress site ( but the old content should be visible too ( So when you visit and not found, it should look at but without changing the domain
    I already found this, http headers aren’t pass.

    function wpd_do_stuff_on_404(){
        if( is_404() ){
            // do stuff
    		global $wp;
    		$current_url = home_url(add_query_arg(array(),$wp->request));
    		//set $url to what's needed 
    $url = str_replace('','',$current_url);
    		$response = wp_remote_get($url);
    		$response_code = wp_remote_retrieve_response_code( $response );
    		//echo $response_code;
    		if ($response_code == 200){
    			echo wp_remote_retrieve_body( $response );
    add_action( 'template_redirect', 'wpd_do_stuff_on_404' );

    Any suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • sorry found a solution, but not with wordpress.
    if i put the next code in htaccess file above the wordpress code it works:

    RewriteCond %{HTTP_HOST}$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$$1 [NC,P]

    sorry i’m to quickly with asking, and i got this idea after 3 hours of searching wordpress

    this breaks wordpress of course! grrr.
    any solutions?

    • This reply was modified 1 year, 1 month ago by  tomwoef.
    Moderator bcworkz


    Why don’t you mirror the old site’s content that should still be accessible on the new site? Redirect any old site requests to the new site. Of course the domain would change, but in this case it’s old to new, not new getting from old, so maybe this change is acceptable. Redirect with status 301 and eventually the old domain will stop being requested.

    You would be better of putting in redirects so traffic to your site gets to the correct content. By putting in content from another site on the old site might cause you issues where SEO is concerned and you may ranked lower in search. I’d suggest using a redirect manager to take visitors to the right page.

    Plugins are available to do this, but you can also do it manually through .htaccess rules but that’s advisory. It takes more time and effort to manage.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pass external url trough if page not found’ is closed to new replies.