How to display "Not Found" instead of automatic redirecting?

How to display "Not Found" instead of automatic redirecting? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How to display "Not Found" instead of automatic redirecting? error on your web browser. Problem :



how to redirect to 404 in .htaccess file ? Example



www.domain.com/ja/any_post or www.domain.com/ja/all_posts

www.domain.com/fr/any_post or www.domain.com/fr/all_posts




A little bit more explaining can't hurt. Example:



My original post is on URL www.domain.com/post.



I had japanese translation of it at this URL: www.domain.com/ja/post.

And also French translation: www.domain.com/fr/post.



I had to delete these translated posts and now when I type www.domain.com/ja/post to my address bar manually, URL is redirected automatically to original post at www.domain.com/post. The same goes for /fr/.



I need URL to stay www.domain.com/ja/post and show "Not found" for all posts (with /ja/ and /fr/ in URL) without using 301 to 404.php.



Here's my htaccess (WordPress):



RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]


Another thing I forgot to point out.../ja/ and /fr/ don't really exist.


Solution :

The simplest method would be:



# Redirect to HTTP 404 File/Page Not Found
Redirect 404 "/ja/any_posts"
Redirect 404 "/ja/all_posts"
Redirect 404 "/fr/any_posts"
Redirect 404 "/fr/all_posts"


Though you could also use:



# Redirect to HTTP 404 File/Page Not Found
RewriteRule ^ja/any_posts$ - [R=404,L]
RewriteRule ^ja/all_posts$ - [R=404,L]
RewriteRule ^fr/any_posts$ - [R=404,L]
RewriteRule ^fr/all_posts$ - [R=404,L]


Or this can be written more efficiently as:



RewriteRule ^(fr|ja)/(all|any)_posts$ - [R=404,L]


Or if you meant to redirect every page in those subfolders then:



RewriteRule ^(fr|ja)/(.*?)$ - [R=404,L]


Edited following comments:



RewriteEngine On
RewriteBase /
RewriteRule ^(fr|ja)/(.*?)$ - [R=404,L]
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]


Something along these lines might do what you want. This will redirect the user to the 'main' version of the page, and add a 404 header in the process, removing the old link:



RewriteCond %REQUEST_URI ^/(ja|fr)/
RewriteRule ^(ja|fr)/(.*?) /$2 [L, R=404]

We hope that this article has helped you resolve the htaccess, redirects, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=