Best way to make a redirect link?

Posted on 2005-04-05
Last Modified: 2010-04-06

Would anyone know the best way to make a redirect link? I need to redirect quite a few links, basically I need to mask where a link goes to, so I guess it would need to be done with php or something. Here is the situation, on my site, users can get reports of their activity on the site, the problem is the link for their report shows the doc directory. It wouldn't take much trial and error for people to find a way of accessing other users docs. The docs are downloadable so I just need a way to mask the destination.

Does anyone know the best way to achieve this? Bearing in mind that the links are generated daily? I know I am probably fishing here so I would accept either some direct suggestions on how to do it or maybe links to redirect scripts or something?

Thanks for your time.

Oh, the site uses a mysql database and runs on an apache server.

Question by:jalexan123
    LVL 15

    Accepted Solution

    use mod_rewrite (
    to redirect from /usename/report.dat to /doc/day/username.dat
    mod_auth to restrict user to /username only.
    LVL 5

    Assisted Solution


    You can probably have a field in your MySQL database that contains links. Then just get it using mysql_query. So you'll have something that looks like this...

    ...some code here...
    $result = mysql_query($sql);

    while ($row=mysql_fetch_array($result)) {
    $link = $row['link'];
    ...your other fields...



    <title>My page</title>
    <script type="text/javascript">
    window.location="<? echo $link; ?>";
    ...the rest of the page...
    LVL 16

    Assisted Solution

    Redirect in php

    header("Location:"); /* Redirect browser */
    LVL 6

    Assisted Solution

    if (!empty($_GET['linkid']))
            $linkid = $_GET['linkid'];
            //now you can treat your links useing any kind of test you want
            //for example from a database like $page = GetPageFromMySQLById($linkid) and write your
            //function to get it from the db
            //then do a: include $page;
            //a simple test here :
            if ($linkid == 1) {
                    include 'path/to/your/page.php'; //will actually include the page without showing its path

    // To test try to show your page with usieing for example something like page.php?linkid=1

    Author Comment


    Sorry I have't been in contact since posting this question. I will give those tries a go and get back to you.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now