Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #884792

    Dears,

    I just stuck with the following question,- whilst the user is typing http://mydomain.com/jhjhkjhkjhkjhj trying to access the absent webpage, website must do the hard redirect to http://mydomain.com/404/ and show the content of 404.php

    I know, there’re to many solutions there, but I didn’t found yet the right one.

    Any idea of how to setup this either through .htaccess (APACHE) or something else?

    #885469

    Hey DimaP,

    Here is a thread for you to consider
    https://stackoverflow.com/questions/19962787/rewrite-url-after-redirecting-404-error-htaccess
    and the Apache docs
    http://httpd.apache.org/docs/2.2/custom-error.html

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #886384

    Hi, Victoria,

    thanks for the suggestion. I just put the below lines into my .htaccess file, and seems it should work, as most suggestions in the web points to this code, but one doesn’t work – when user types something like http://mydomain.com/jhjhkjhkjhkjhj trying to access the absent webpage, website don’t do the hard redirect to http://mydomain.com/404/

    Any idea of how to fix? Maybe something need to be done within the 404.php ?

    ErrorDocument 404 http://mydomain.com/404/

    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^/404/$
    RewriteRule ^(.*)$ /wp-content/themes/enfold/404.php [L]

    #886993

    Hi,
    Where do you want 404’s to land if not the 404 page?

    Best regards,
    Mike

    #887073

    Hi,
    404 page exists as a part of Enfold, and it is there, /wp-content/themes/enfold/404.php

    But the issue is that once the user types something wrong as e.g. http://mydomain.com/jhjhkjhkjhkjhj, and that page don’t exist, the browser redirects him to the http://mydomain.com/404/, showing this exact url also showing 404.php

    In my case, browser shows 404.php indeed but not showing the http://mydomain.com/404/

    #887198

    Hi,
    Ok, try creating a new page in WordPress and name it 404, and save. Be sure the url reads 404 and not 404-2 as mine did. I got past this point by naming it 4o4 (that is the letter o)
    Then add this code to the end of your functions.php file in Appearance > Editor:

    function error_page_rewrite( $wp ) {
        if (is_404()) {
            wp_redirect( home_url( user_trailingslashit( '4o4' ) ) );
            exit;
        }
    }
    
    add_action( 'wp', 'error_page_rewrite' );

    *Note this has the 4 letter o 4 – change to suit you.
    Now when you type jxjxjxjxj you will be sent to the 4o4 page and the url will only read http://www.yoursite.com/4o4/

    Best regards,
    Mike

    #887535

    Thank you, Mike, everything is started to work as a charm! )

    #887775

    Hi,

    Great, glad you got it working. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #887784

    Hi, please close the ticket. Thank you.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.