Mobile app version of vmapp.org
Login or Join
Goswami781

: How to display "Not Found" instead of automatic redirecting? 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

@Goswami781

Posted in: #Htaccess #Redirects

how to redirect to 404 in .htaccess file ? Example

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

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

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

I had japanese translation of it at this URL: domain.com/ja/post. And also French translation: domain.com/fr/post.
I had to delete these translated posts and now when I type domain.com/ja/post to my address bar manually, URL is redirected automatically to original post at domain.com/post. The same goes for /fr/.

I need URL to stay 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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Goswami781

2 Comments

Sorted by latest first Latest Oldest Best

 

@Martha676

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]

10% popularity Vote Up Vote Down


 

@YK1175434

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)/(.*?) / [L, R=404]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme