简体   繁体   中英

redirect a url to an HTML page

I am trying to route an external webpage to a local file on my machine.

For example:

https://example.org/something/page.php

should redirect to:

c:\local.html

I don't want to redirect all traffic from that domain, only this particular page.

I do not have access to the website so I can't change it.

It's a PHP script. This means you can use PHP's header() function to do what you need.

You'd use it like this:

<?php
    header('Location: file://path/to/file.html');
?>

If you want to redirect to a different page on the same server simply use

<?php
    header('Location: /path/to/file.php');
?>

This would cause all traffic that lands on that page to be redirected to that local path.

For the best performance you'd want to put this at the top of your script so that the page does not execute more PHP code than needed.

Also do note that any local files will not be visible for other users visiting your page on the interweb.

This means that whenever someone lands on page.php he or she will be redirected to the same path on their local PC so if that is not there they will get a 404 of some kind.

If you want it to happen immediately as you visit the page, add this inside your <head> -tag.

<meta http-equiv="refresh" content="0; url=file:///c:/local.html" />

Same can be achieved with Javascript, if you add this to your <script> -tag inside your <head> -tag.

window.location = "file:///c:/local.html"

And since I see you're using PHP, this might be ideal to you as well:

header('Location: file:///c:/local.html');

Using either one works, but I would prefer the PHP option. Simply add it inside your <php> -tag (at the top would be prefered).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM