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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts

    htaccess redirect

    Hello All,

    I have a dynamic url that i would like to redirect to a details page... I'm new to .htaccess files

    here is what i have so far:

    link that has to forward to www.hedgevent.com/details/eventdetails.php :

    PHP Code:
    <a href="http://www.hedgevent.com/details/'.$urlevent.'.php?id='.$id.'" class="event"
    here is an example linked url: http://www.hedgevent.com/details/Coc...und.php?id=100


    what kind of scripting do i need to include in the htaccess file and on the receiving page (eventdetails.php) so that they connect??

    Thank you in advance for your help.
    Last edited by jchrisphonte; 01-30-2012 at 04:54 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Wut? PHP hasn't a thing to do with .htaccess, the only thing that you *may* want to do is determine if mod_rewrite is in use and rewrite the links if you desire.
    The receive page doesn't change. Mod rewrite links a url to a querystring, so the standard GET still applies to the script in use.
    If you want to redesign the links, the very first step is adding an environment variable within .htaccess to declare that rewrite engine is on. Once that's complete, you can fetch that out of PHP and design your urls to match. For example:
    PHP Code:
    if (isset($_SERVER['HASREWRITE'])) // Your environment variable
    {
        
    printf('Link: http://yoursite.com/article/%d'$articleid);
    }
    else
    {
        
    printf('Link: http://yoursite.com/article.php?articleid=%d'$articleid);

    There is no automagic way to rewrite these, although use of an output buffer and replace may make it a lot easier so you don't have to manually write code like this. Becomes interesting though as you need a solid set of rules to work with.

  • Users who have thanked Fou-Lu for this post:

    jchrisphonte (01-30-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    thanks for clarifying Fou lu... I 've been stumped with this for 4 days now and maybe i should explain it simpler instead of assuming all the information I received in the past was accurate.

    I am trying to get links on this page under upcoming events: www.hedgegevent.com to go to a details page when clicked.

    Is it possible to make one details page and have all the links go here with unique information for each event??

    please do let me know if i was wrong to think this was an htaccess type of query??

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by jchrisphonte View Post
    thanks for clarifying Fou lu... I 've been stumped with this for 4 days now and maybe i should explain it simpler instead of assuming all the information I received in the past was accurate.

    I am trying to get links on this page under upcoming events: www.hedgegevent.com to go to a details page when clicked.

    Is it possible to make one details page and have all the links go here with unique information for each event??

    please do let me know if i was wrong to think this was an htaccess type of query??
    Without following links since I'm at work, the answer is yes. That's PHP's job, to take input from the user in the form of either a querystring in get, or through other means like cookies, post and put, and use that data to dynamically generate what the content will be.
    From development world, you completely ignore the use of mod rewrite. This is an added feature to convert a querystring into a slightly more readable approach. If you centralize a location to perform all the link building, then you can easily provide the data required, and write the rules to change between a querystring and a seo style link with minimal effort.

  • Users who have thanked Fou-Lu for this post:

    jchrisphonte (01-30-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    i guess my question is -- if all the urls are different:

    examples.
    http://www.hedgevent.com/details/Coc...und.php?id=100
    http://www.hedgevent.com/details/Dis...mit.php?id=124

    how do i get these links to end up at the same place?? or to make sure I understand you, do I need to?

  • #6
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    you just change them to all point at the one page my_display.php (or something like that) and use the id=xxx as the identifier on the display page

    so the 2 example links would be
    http://www.hedgevent.com/details/my_display.php?id=100
    http://www.hedgevent.com/details/my_display.php?id=124

    the id's 100 + 124 will be what you use to get the detail for the specific event out of the db and display it

  • Users who have thanked jmj001 for this post:

    jchrisphonte (01-31-2012)

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    great!!! I understand now...

    one last question and I will be forever in your debt, how could i rewrite the above example urls to include the event name yet still point to the file?? A big component of this site would be the SEO friendly url for the event names coming up in search engines... would I have to include the event name after the "?" as well?

  • #8
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    there's not really any need because on the receiving page you can extract it from the database along with your query for the other detail...

    however...

    if you really really want to you can simply make the link to be:
    http://www.hedgevent.com/details/my_...s_On_The_Sound

  • Users who have thanked jmj001 for this post:

    jchrisphonte (01-31-2012)

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    ok thanks jmj. I appreciate your help.

    http://www.hedgevent.com/eventdetail...e_Sound?id=100
    hedgevent.com/details/my_display.php?id=100&name=Cocktails_On_The_Sound

    which one of the above would a search engine be able to pick up??


  •  

    Posting Permissions

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