SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Perm Redirect

  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Perm Redirect

    I have a domain that has 1000's of pages and some how google is locating my unfriendly urls; domain.com/?epi=293

    How would i best approach the 301 redirect? I know i can assign each link in HTAccess however i'm not going to put thousands of links into it. Would I use php redirect header? how does wordpress do it?

    so everytime someone or google goes to domain.com/?epi=293 should redirect to domain.com/friendly_url_here.html
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well ?epi=293 would default to the DirectoryIndex directive set in your htaccess, which defaults to index.php

    So, I would just do the redirect in PHP.

    So something like this in index.php (or whatever u want to set it in htaccess)

    PHP Code:
    if ($_GET['epi']) {
        
    $url get_new_url($_GET['epi']); # query where the new URL is
        
    if ($url) {
            
    header ('HTTP/1.1 301 Moved Permanently');
            
    header ('Location: '.$url);
            exit;
        }


  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's what i figured.

    Your script looks like it'll check $_GET['epi'] regardless. If the url was friendly domain.com/name_of_url.html
    epi would return name_of_url

    I was thinking of checking the full url.

    If full url is http://www.domain.com/name_of_url.html then its fine

    If full url is http://www.domain.com/?epi=293 then i would do the Perm Redirect.

    looks like i was on the right track.. i thought there would be a HTAccess secret ingredient.

    This is my Fullurl script

    Code PHP:
    function sselfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = sstrleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } 
    $FullURL = sselfURL();
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.


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
  •