What is the best way to learn to use URL rewrite using php and MySQL?

Discussion in 'Web Design' started by Glenn, Oct 15, 2013.

to remove all ads.
  1. Glenn

    Glenn Member

    Messages:
    202
    I want it to read the database for an article and have a field with the new url.

    Where can I read a step by step way to do this?
     
  2. ronaldroe

    ronaldroe Super Moderator Staff Member

    Messages:
    1,223
    The Googles
     
  3. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,670
    EXACTLY as you would with 'dynamic' URLs

    site.tld/this-is-a-long-url/ only serves the content from site.tld?doc=54321 it does not change the fundamental operation of code and database interaction.
     
  4. Glenn

    Glenn Member

    Messages:
    202
    Ok, so where is a good step by step explanation of how to do it?
     
  5. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,670
  6. Edge

    Edge Member

    Messages:
    461
    Threads started by Glenn

    You ever posted any answers to anything? I would have thought by now that after asking that many questions you would be immensely knowledgeable...
     
  7. Glenn

    Glenn Member

    Messages:
    202
  8. Glenn

    Glenn Member

    Messages:
    202
    A time or two. I'd like to get to that point but I'm really not using it enough to be really good at it. I have a lot of good ideas, just not the time to follow through with them fully because of my full time job so what I learn is not real strong due to lack of using it.
     
  9. ronaldroe

    ronaldroe Super Moderator Staff Member

    Messages:
    1,223
    Don't let that stop you. You just have to make time. Trust me, I've been doing it for years. Sure, I can't dedicate as much time as others who do it full time, but I work it in. You can too.
     
  10. Glenn

    Glenn Member

    Messages:
    202
    Yes, I'm a full time teacher. What I'm saying that I don't have time for is to work on my ideas so I don't practice the web design that I learn. Each time I work on it, I have to go back and read up on what I'm doing. Most of the time now, I know enough to search for what I need. Or at least to ask the right questions.
     
  11. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,670
    :)

    You know what they say, ....


    Those who can, do.

    Those who can't ... teach ;) :)


    Which is always a good sign.
     
  12. Glenn

    Glenn Member

    Messages:
    202
    ok, I have read a lot and have made some changes.


    I have in my .htaccess:
    RewriteEngine On
    RewriteRule ^(.*)$ /index.php?artid=$1


    I have been told to set $newUrl = $_GET['newUrl']; ?

    how does this work when I do not have a newUrl set in the address bar?

    Currently, if I type mysite.com/bunchofstuff-here it will load my home page, which tells me that I have done something right so far.
     
    Last edited: Oct 24, 2013
  13. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,670
    What a URL rewrite actually does is make a second internal HTTP request for the REAL URL that delivers the content, it doesn't do anything magically with the URLs, it simply masks or aliases where content actually is being served from.

    Code:
    RewriteRule ^(.*)$ /index.php?artid=$1
    

    In English says;
    for ANY number of characters between the start (^) of, to the end ($) of. the URL string that is requested at this server, request and serve the content from site.tld/index.php?artid=[the any number of characters matched by the regular expression]

    so
    Code:
    site.tld/this-is-the-dogs-bollocks-you-know
    would be re-sent to the server as

    Code:
    /index.php?artid=this-is-the-dogs-bollocks-you-know
    
    So just as long as your server side code can find the right content indentified by "this-is-the-dogs-bollocks-you-know" it will be delivered to the user agent.
     
  14. Glenn

    Glenn Member

    Messages:
    202
    Just to experiment around, I put in my .htaccess file:
    RewriteRule ^(.*)$ /index.php?newUrl=$1

    Then I put in my index.php file:
    $newUrl = $_GET['newUrl'];
    echo "newUrl", $newUrl;

    All I get out of this is "newUrl"
     
  15. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,670
    What was the URL requested?
     
  16. Glenn

    Glenn Member

    Messages:
    202
    It's working now. I have to rewrite a few things now and see if everything works right. I'm 3 hours into parent teacher conference and I have had one parent so I have a little time here.
     
  17. Glenn

    Glenn Member

    Messages:
    202
    Everything seems to be working great. Thanks for the help.
     

Share This Page