Esteban Cazorla
Esteban Cazorla

Reputation: 151

Relative links on a custom 404 page

I have a personalized 404 error page in my web, with

ErrorDocument 404 404.htm

in my .htaccess.

The problem is, if you type www.mydomain.com/whatever/whatever2.html, it shows the 404 page correctly, but the links are all broken, for example a link to href="property.php" points to www.mydomain.com/whatever/property.php, that is a 404 error too.

How can I fix this without changing all the routes to absolute routes?

Upvotes: 3

Views: 1447

Answers (3)

human
human

Reputation: 461

 <base href="/"> 

does not work with google Adsense/Analytics. Division zero.

Because the Error 404 page has to be able to run from any URL my 404.php simply contains

<?php
header("Location: http:/homepage.de");
?>

This way it relocates to the base URL.

Upvotes: 0

Tripp Kinetics
Tripp Kinetics

Reputation: 5439

Instead of using relative paths like:

href="property.php"

Try using absolute paths like:

href="http://www.example.com/path/to/property.php"

Upvotes: 1

anubhava
anubhava

Reputation: 785098

You can add this in the <head> section of your page's HTML: <base href="/" /> so that every relative URL is resolved from that base URL and not from the current page's URL.

Upvotes: 5

Related Questions