Results 1 to 10 of 10

Thread: Permanent Redirects

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Permanent Redirects

    I have a site with 100 pages indexed but I want to change the overall design and structure of the site. The URL's will be totally different

    Is there any script or function in PHP which I can use to redirect them permanently to the new URL's?

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,734
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    I'm just piggy backing a question on here as well: what does it mean to have 100 pages indexed? mostly curious about the word index...

    Just to put in my 2 cents worth as well, when password protecting a page I often use the following that is placed at the top of my page which will redirect a person to an alternate page of my choice if they are not logged in:
    PHP Code:
    <?php
      session_start
    ();
    if ( @
    $_SESSION['pasword']  != "tweetybird" )
    {
    header("location: ../login.php");
    exit();
    }
    ?>
    Not sure if that is what you are looking for though.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    header("location: ../login.php");
    The Location header must be an absolute URI:
    Code:
    header('Location: http://www.example.com/path/to/login.php');
    Hasan, PHP isn't your best option for this. You can do it, but you'd need to create a page for every old page you want to redirect; hardly an efficient solution. Instead, you might want to write a .htaccess file with a redirect:
    Code:
    Redirect 301 /page1.html http://www.example.com/page2.html
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,734
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    The Location header must be an absolute URI:
    why? The code I posted I actually copied from one of my files. I added the ../ just to shorten it a bit for simplicity and to redirect it to the parent directory. Then again if the redirect is toa completly different website the the url would have to be absolute as well.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Local paths work, but they aren't standard and may not work in all browsers. "Use at your own risk", I suppose.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    RFC 2616, section 14.30 Location:
    The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,734
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Thanks for explaining. I didn't know that. Some of what is in that quote I didn't really understand, but that would be a question for a separate thread. However, why am I able to go to a parent directory in that way? What is the original, or correct, purpose of the ../ ?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What is the original, or correct, purpose of the ../ ?
    Exactly as you have used it: to access a directory above the current one. There's no problem with this, even in absolute URLs: you can quite happily do something like http://www.example.com/lorem/ipsum/dolor/sit/../amet.html to access http://www.example.com/lorem/ipsum/dolor/amet.html. The .. construct itself has no bearing on the issue I'm addressing here.
    why am I able to go to a parent directory in that way?
    I'm not sure this is exactly the question you were asking, but you are able to use relative URLs in Location fields because a lot of browsers have implemented this as a feature. However, it is still non-standard, and as such cannot be relied upon.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What else can be done to get rid of it then?

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Get rid of it? You don't need to get rid of it, just use an absolute URL.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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