Pregunta

First of all, my ErrorDocument 404 /v1 is never redirecting, but if I look in the Chrome Inspector, I really have a 404 error. At first I thought it was because I really needed to specify a file ex: error.html, but that didn't work either. /v1 is just a wordpress subdomain, and I want to redirect all of my errors there. /v1 falls on my homepage of my subdomain.

Also I would like to make the error page dynamic, but I can't figure how to do that. Something like that:

RewriteCond %{REQUEST_FILENAME} public_html/(.*)
ErrorDocument 404 /v1/%1

Any ideas? Thank you!!

¿Fue útil?

Solución

You're goinmg to need to return the 404 through a php script:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /404.php?path=$1 [L]

And in the 404.php file:

<?php
header("HTTP/1.0 404 Not Found");

print('The file that you requested: ' . $_GET['path'] . ' was not found\n');

// or include a special 404 page

include ('/path/to/' . $_GET['path']);
?>

Or you could lose the ?path=$1 part completely and just look in $_SERVER['REQUEST_URI'].

Otros consejos

This syntax is incorrect:

RewriteCond %{REQUEST_FILENAME} public_html/(.*)
ErrorDocument 404 /v1/%1

Because ErrorDocument has no connection with RewriteCond (mod_rewrite) and it is unconditional.

Conditional 404 handling example:

ErrorDocument 404 /404.php
RewriteRule ^foo/ - [L,NC,R=404]

I use this syntax! Usually works!

ErrorDocument 404 "<script>window.location.href='404.php?page='+window.location.href.split('/')[window.location.href.split('/').length-1];</script>"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top