Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I add a 301 php variable redirect in an existing file?

    How could I redirect a php variable on an existing/working index.php file. I only want to redirect the variable(s).


    I would like the redirect a series of variables (?option):
    -index.php?option=com_content&task=view&id=70&Itemid=40 to point to folder1
    -index.php?option=com_content&task=view&id=70&Itemid=42 to point to folder2
    etc


    Could it be a little like this?

    <?php
    if(isset($_GET['option']) && $_GET['option'] == "?option=com_content&task=view&id=70&Itemid=40 "))
    {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.com/folder1");
    // at this point you should not really use exit .
    }
    if(isset($_GET['option']) && $_GET['option'] == "?option=com_content&task=view&id=70&Itemid=41 "))
    {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.com/folder2");
    // at this point you should not really use exit .
    }
    ?>

    Would I have to paste that into the fully working index.php?

    Many thanks for the help!

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by janaro View Post
    // at this point you should not really use exit .
    why ?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got this code from a friend who new how to create a redirect between one location and the other....

    Can you help with redirecting my variable?

    Thanks

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    For starters you code has loads of errors, such as the $_GET['option'] var cant equal the string as you cant use the $_GET var to get the full query string you would need to use $_SERVER['REQUEST_QUERY'].

    Secondly are you trying to make all prams equal something then redirecting to the url for them prams?
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I'm open to changing it or starting from zero (I'm not much of a coder).

    I familiar with the:

    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.com/newpage.html");
    exit();
    ?>

    And then to save as the oldpagename.php

    But what code would I have to insert into my already working index.php to redirect may variables to it's corresponding pages or folders?

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    are you using any form of storage such as a mysql database to store information into?
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •