Php linking and search engine friendly urls

Discussion in 'PHP' started by hasbehas, Jan 21, 2007.

  1. #1
    I have function that includes a htm file also title with the same name txt
    so it looks like "domain.com/details.php?content=Aboutus"
    I am thinking of changing this with sef urls like "domain.com/Aboutus"

    I have the htaccess examples. But could not figure out the a href part.

    Any ideas ?
     
    hasbehas, Jan 21, 2007 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you don't have to be bothered about the html tags (i.e. the <a href..> part)... for mod rewrite, the engine is only focusing on the actual urls and will know how to exclude the html tags.

    :)
     
    daboss, Jan 21, 2007 IP
  3. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #3
    What I mean by the href part is ;
    when I setup modrewrite everthing works fine.
    say that my link is domain.com/details.php?content=aboutus
    If I call domain.com/aboutus works fine.
    But my problem is what to write to href part. If I type "domain.com/details.php?content=aboutus" to href then this address comes up.
    The part that I need is the Php function that will allow me to call what ever the function would be to interprete the link from normal link (details.php?content=aboutus) to sef link (domain.com/aboutus)

    You see , I dont want my hrefs to be the sef type like .com/aboutus
    I need a function like
    
    <?link(aboutus);?>
    
    Code (markup):
    which will interprete the link. If modrewrite is working then address will come up as sef. If not address will comeup like old style not sef.
     
    hasbehas, Jan 22, 2007 IP
  4. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #4
    no help with this ?
     
    hasbehas, Jan 23, 2007 IP
  5. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Maybe just create a config file where you can have a setting like:

    $cfg_rewrite = true;
    PHP:
    Then in your 'link' function you could just check the setting above like:

    function make_link($link)
    {
        global $cfg_rewrite;
    
        if ( $cfg_rewrite === true )
        {
            return $link;
        }
        else
        {
            return 'details.php?content='.$link;
        }
    }
    PHP:
    I think I get what your saying, but maybe not.
     
    chopsticks, Jan 23, 2007 IP
  6. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #6
    Thanks.. This was exactly what I have tried to say. I will try this function. Perhaps improve a little. I will keep posting it from here..
    Thanks
     
    hasbehas, Jan 23, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just wanted to add: there's no 'native' PHP function that will convert your URLs for you (especially automatically), for a couple of reasons:

    1) htaccess is an Apache thing. PHP needs to work with IIS and so on..
    2) there's no reason why you don't want to be able to access a page by both 'URLs'.

    chopsticks' example will work for 'simple' pages but once you get bigger, things will get messier...
     
    TwistMyArm, Jan 23, 2007 IP
  8. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #8
    Ofcourse I would like to access the URL with both ways.
    The part that I need is to create a PHP function that will dedect and write the href tag.

    So now by modifiying the htaccess file I can access the url as domain.com/ephesus and also domain.com/details.php?content=ephesus without doing any php work.

    But the href tag has to be either href="details.php?content=ephesus" or href="/ephesus"

    So I did not want to the href in the files to be either of them. I wanted to use like the chopsitcks linking function. href="<?make_link(ephesus)?>"

    BYTWY; I could not get chopsticks function to work :( So I have revised it alittle.

    
    // linking SEF
    $cfg_rewrite = true;
    function makelink($link)
    {
    global $cfg_rewrite;
    if ( $cfg_rewrite === true )
    {
    echo $link;
    }
    else
    {
    echo "details.php?content=$link";
    }
    }
    // linking SEF ends
    
    PHP:

    href tag is ;
    
    href="<?makelink("ephesus");?>"
    
    Code (markup):
    Thank you guys..

    And for the htaccess I have done ;

    RewriteRule ephesus details.php?content=ephesus [L]
    RewriteRule about-us details.php?content=about-us [L]

    one by one.

    Is there way to include all these links on one line ?
    like : ^$link details.php?content=$link*
     
    hasbehas, Jan 23, 2007 IP
  9. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #9
    picouli, Jan 24, 2007 IP
  10. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #10
    cheers.. ;)
     
    hasbehas, Jan 24, 2007 IP