SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: mod_rewrite

  1. #1
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite

    Hello,

    I am going to have 5 different pages and the URL is going to look like this:

    Code:
    tdn.php?page=blahblah
    Now how can I transform this into:

    Code:
    myurl.com/tdn/blahblah
    How can I do this? What would the code for my .htaccess file look like?

  2. #2
    SitePoint Enthusiast lix0r's Avatar
    Join Date
    Feb 2006
    Location
    Norway
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The htaccess code would look like this:
    HTML Code:
    RewriteEngine On
    RewriteRule ^tdn/(.*)$ tdn.php?page=$1 [L,NC]

  3. #3
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Read this article and then try to write some code. If you have problems post it here and we'll try to help you.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Tipem,

    YOU have to write the blahblah code in your links - mod_rewrite can redirect to the actual script.

    lix0r was on the right track but I LOATHE the indiscrimate use of the EVERYTHING atom like that. If you know that "blahblah" is going to be one or more lowercase letters, then use ([a-z]+). His solution will give you tdn.php?page= and you'd better be able to handle that in your script!

    My signature's article also has an article which has helped members - it was designed to prevent my retyping the same answers over and over to common questions and should answer yours, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Enthusiast lix0r's Avatar
    Join Date
    Feb 2006
    Location
    Norway
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe! I didn't mean to offend you dklynn I just copied the lines straigh out of my .htaccess file. And I do let the script handle what's in the everything atom. This is because I both pass id-number and plain tex through there :P

    You article was pretty good though, and I'll try to avoid using (*.) in the future

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    lix0r,

    No offense taken - just my normal rant about the everything atom 'cause it can (and DOES) cause so many problem for those who are not aware. I don't like to tell newbies to use that UNLESS they MEAN to capture EVERYTHING and redirect it in such a way as NOT to loop.

    Glad that you liked the article - as I'd said, it was meant to prevent repetitive typing.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your article is very interesting, dklynn, but I am still failing to learn how to actually write the coding.

    I have decided to use a different structure in the URL...

    THIS:

    Code:
    viewcontent.php?type=guide&page=whateverthepageishere
    TO THIS:

    Code:
    myurl.com/viewcontent/guide/whateverthepageishere
    How can I do this?

    -----------------------------------

    EDIT: I think I've found the right coding:

    Code:
    RewriteEngine On
    RewriteRule ^viewcontent/(.*)/(.*) /viewcontent.php?type=$1&page=$2
    Last edited by Tipem; Feb 13, 2006 at 17:42.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    tipem,

    [rant][repeatedly]WHY would you use the EVERYTHING atom when you know that you will only use lowercase letters?[/repeatedly][/rant]

    Otherwise, okay.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •