Trevor Clissold
Trevor Clissold

Reputation: 85

Redirect from a page URL to another page

Basically, a colleague has sent out a poster with a web address on it as example.com/pagename, however, when we create a page on our website it automatically creates the URL as

  example.com/view/pagename 

Is there a way that I can redirect the URL he has put on the poster to go to the actual URL of the webpage? Not sure if there's something I can put on the server or if I do this through our host (1and1).

Do you have any ideas?

Upvotes: 2

Views: 110

Answers (3)

Sarath Mohan
Sarath Mohan

Reputation: 167

In that page you can user the header function in PHP.

so in page example.com/page1.php, use like

header("location: example.com/page2.php");

so when page1 loads it will automatically redirect to page2

Upvotes: 1

tbraun89
tbraun89

Reputation: 2234

A simple and fast solution is to create a foler pagename on your document root and add a index.html file in this folder with this in the header:

<meta http-equiv="refresh" content="0; url=http://example.com/view/pagename" />

You can also add a JavaScript redirect and a link with the right URL for the redirect so if a browser doesn't support JS or HTML redirects the user can always use the direct link.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="refresh" content="0; url=http://example.com/view/pagename" />
        <script type="text/javascript">
            window.location.href = "http://example.com/view/pagename";
        </script>
    </head>
    <body>
        If you are not redirected automatically, follow the <a href="http://example.com/view/pagename">link to pagename</a>.
    </body>
</html>

Upvotes: 1

Jonathan
Jonathan

Reputation: 2877

You could achieve this very easily by adding a .htaccess rule, assuming you are using apache as your web server.

.htaccess

Redirect 301 /pagename /view/pagename

Upvotes: 1

Related Questions