Ok-Alex
Ok-Alex

Reputation: 558

htaccess reditect if server returns 404

For example I have a page http://www.f1u.org/en/its-interesting/166-cricri. How to write rule: if that page exists - open it. If it returns 404, then redirect to http://www.f1u.org/its-interesting/166-cricri

Upvotes: 0

Views: 179

Answers (2)

Charlie
Charlie

Reputation: 7349

It sounds like you want the apache server to look ahead to see if the current URL exists, if not, redirect them. I think you might be able to use mod_rewrite to accomplish this.

My first stab at it would be something like:

RewriteEngine On
RewriteCond %{IS_SUBREQ} false
RewriteCond %{REQUEST_URI} !-U
RewriteRule /en(/.*) $1 [R,L]

I'll note that I haven't tried it so the syntax and effects could be slightly off, and you'd need to be careful that you don't put yourself into an infinite loop, or wind up with too many subrequests (as that could impact the performance of your server). But hopefully it'll give you a starting point to play with. Alternatively mod-rewrite could (depending on server permissions) let you invoke scripts to determine rewrites as well, which could be an option as well.

Upvotes: 0

Bhanu Prakash Pandey
Bhanu Prakash Pandey

Reputation: 3785

use this line in .htaccess file

ErrorDocument 404$ http://www.f1u.org/its-interesting/166-cricri

Upvotes: 1

Related Questions