SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    another url redirect with .htaccess question

    Greetings to everyone. I'm new at this forum and also new to programming in php.

    I posted my first website on another forum for review and everyone said it was sh*t and they were true. One of the bad things are urls and links. I used $_get in urls which was bad for seo.
    Now I'm learning how to rewrite urls with .htaccess for the past 7 days and still don't get it.

    I've learned regular expressions (at least the parts that i need) and I've managed to redirect to other scripts that don't have GET paramaters atached to it, but with GET i can't and don't understand. I've read all the forum threads, stackoverflow posts and .htaccess tutorials and tried .htaccess generators (who i don't want to use beacuse i want to learn) but still don't get it.

    This is my problem.

    I have a website that has a product list. In the product list, there is a link for 'Details' on a product. The url is constructed from data fetched from a database like a name and an id so i could access the data in the file that the url points to. The link is as follows

    http://www.exampleurl.com/Article-pr...-from-database

    Now, this link is in index.php, the starting document.

    The file i which to be redirected is products.php?id=12 or some other id number. It depends on the product id fetched from the database.
    So i wrote the rule like this...

    RewriteRule ^Article-([a-zA-Z])/([0-9]+)/? products.php?id=$1

    So, the url has two parts. The first is the name of the product that has to be in url. The name of the product is known by the 'Article-', then a regular expression for the actual name. Then, the id. Now, this works. Lets say my products name is 'Coffie' and id is 56. My url gets rewritten to www.example.com/Article-Coffie/56 but 404 error arises. The server can't find products.php. Why?

    All the help is welcome.

    Thank you in advance.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,268
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    RewriteRule ^Article-([a-zA-Z]+)/([0-9]+)/? products.php?id=$1
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    RewriteRule ^Article-([a-zA-Z]+)/([0-9]+)/? products.php?id=$1
    Thank you for your answer. After a week of exploration, I finally got the hole .htaccess rewritte url sh*t about an hour after i posted this. I cannot describe the happiness i fell at this moment. .

    Very big thanks for your answer


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
  •