SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member Wardy7's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite for newbie

    I know there are a number of posts about mod_rewrite and I've looked at them but I'm still stuck!

    What I want to do is change urls that look like this
    mydomain.com/toys.php?toy=3
    to
    mydomain.com/toys/3

    This is what I have in the .htaccess file

    RewriteEngine on
    RewriteBase /
    RewriteRule ^file/([0-9]+)/?$ /toys.php?toy=$1 [L]

    I have placed this in the www. folder too.

    Anyone able to help a mod_rewrite newbie

    Cheers
    Wardy

  2. #2
    SitePoint Zealot Polo's Avatar
    Join Date
    Mar 2004
    Location
    United States
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    RewriteRule ^toys(.*) toys.php?toy=$1

    see if it works...

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^toys/([0-9]+)$ toys.php?toy=$1 [L]
    Try that

  4. #4
    SitePoint Member Wardy7's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers guys for the replys, it's mucho appreciated, ta

    I'm still not seeing the changes that I *expect* should happen, but it may be down to something I'm not doing.

    [edited to remove link as example is no longer there]
    The links are still getting displayed in the same format as before.
    If you click on the first link it takes you to a page with 3 example toys, then clicking on one of the toy links takes you to information about the toy (yeh, I know there aren't very exciting looking toys )

    So basically, the toys.php page displays all the toys and clicking on one of these links takes you to the toy which is on toy.php?toy=1 (notice that the page that displays the actual toy details is toy.php and not toys.php if that makes any difference)

    I have tried both examples you guys have left, they may work and it's because I've not done something else that needs doing?!

    Thanks again for your help, just hope I make sense

    Cheers
    Wardy
    Last edited by Wardy7; Mar 26, 2004 at 05:59.

  5. #5
    SitePoint Member Wardy7's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cancel all I just said, 1 minute after posting it I figure out my problem

    I forgot to change one of the toys in the code you gave me to toy (thats my faults for giving you wrong info to begin with) and also forget to change the code on the toys.php page to point to the new address for the new pages
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^toy/([0-9]+)$ toy.php?toy=$1 [L]

    1 other quick question then, say if I have a number of different pages, do I just need to alter this line for whatever pages I need down the page like I have shown below?!

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^toy/([0-9]+)$ toy.php?toy=$1 [L]
    RewriteRule ^bag/([0-9]+)$ bag.php?toy=$1 [L]
    RewriteRule ^car/([0-9]+)$ car.php?toy=$1 [L]

    Anyway, thanks for your other replys guys, excellent stuff, you've made me well chuffed

    Cheers
    Wardy

  6. #6
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    That should work, but I'd imagine you want to change the toy=$1 to bag and car respectively

  7. #7
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In addition to what said by Cam then you could spare two lines and cover the trailing slash too ( by adding /? )

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^(toy|bag|car)/([0-9]+)/?$ $1.php?$1=$2 [L]



    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


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
  •