SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Product Title Slug In Link

    Hi,

    I have a link that works by using a unique identifier product code. However I am trying to put the product name into the link but I am so far stuck with this.

    Does anyone have any suggestions please?

    Code:
    This works..
    
    /products/product/6550
    
    This doesn't work..
    
    /products/product/6550/clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red
    htaccess file..

    Code:
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    # Rewrite Rules
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    </IfModule>

    Code:
    <div class="productimageborder"><a href="/products/product/<?php echo $row['product_id'] . '/' . $row['linkname']; ?>" ><img src="<?php echo $row['image_link']; ?>" alt="<?php echo $row['name']; ?>" /></a></div>

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    This works..

    /products/product/6550

    This doesn't work..

    /products/product/6550/clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red
    Ironically, based on your htaccess file, it looks like the first should not work and the second should. Are you sure we're seeing your full and latest htaccess?
    "First make it work. Then make it better."

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Affirmative,

    That is the latest htaccess file.

    I tried the link with the product id second and it still fails.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    I re-created your setup -- PHP script at /products/product.php and copy-pasted your htaccess -- but everything worked exactly like it was supposed to. So you've got something funky going on somewhere that we haven't seen. My best *guess* is that you have another htaccess file with different code somewhere in that directory path.
    "First make it work. Then make it better."

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Brilliant thanks,

    The link to the products with the product title in now works. However all the other links on the site no longer work.

    Do I need to add a second variable to all the links or is possible to have links with both one and two variables in?

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

    wilderness-wally.com does just what you're asking for and the information you're seeking is in the tutorial linked in my signature - just ignore the comment which will follow this post.

    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
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    just ignore the comment which will follow this post.
    dklynn is referring to me, and the comment he wants you to ignore is that his tutorial in several places contradicts the official Apache documentation and contradicts observable behavior in Apache, and that you'd be much better off learning from the official Apache documentation.
    "First make it work. Then make it better."

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    The link to the products with the product title in now works. However all the other links on the site no longer work.

    Do I need to add a second variable to all the links or is possible to have links with both one and two variables in?
    I'm presuming that you found and removed some other htaccess file? Where did that file live and what was in it?
    "First make it work. Then make it better."

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have constructed landing pages such as .com/products/widgets/red

    So the widgets is a page that is a dedicated page with content with widgets on and red sorts the database and display red widgets.

    My links now longer work to these pages. Can anyone advise how I now get these to work.

    The problem is I am not adding a query at the end so I am stuck on how to fix this.


    Code:
     RewriteRule ^/products/widgets/red/(.*)$ /products/widgets/red [QSA,L]

  10. #10
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually this will solve it but the problem I have is that I cant make the link work with letters, but it will work with numbrs.

    Can anyone advise how I can get it to work with letters?


    This works with numbers..

    Code:
    RewriteRule ^articles/articlesfiltered/([1-9]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
    But I need to use letters. But with letters it doesn't work.

    Code:
    RewriteRule ^articles/articlesfiltered/([a-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]

  11. #11
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Any suggestions please. Once I can run queries on letters it should work fine.

  12. #12
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Actually this will solve it but the problem I have is that I cant make the link work with letters, but it will work with numbrs.

    Can anyone advise how I can get it to work with letters?


    This works with numbers..

    Code:
    RewriteRule ^articles/articlesfiltered/([1-9]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
    But I need to use letters. But with letters it doesn't work.

    Code:
    RewriteRule ^articles/articlesfiltered/([a-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
    I'm sorry to have to give you the same kind of answer, but the change you posted to make it work with letters instead of numbers is correct, so if it isn't working, then there's some other contributing factor that we haven't seen here.
    "First make it work. Then make it better."

  13. #13
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    What I have is a blog. When I use the unique number of the blog post code works fine. But when I try to filter it by the category for example "General" and use [a-z] I cant get the code to work.

    But when I replace "General" with a number such as "1" and used [1-9] I can get the code to work.

    But with this filter I am using letters.

  14. #14
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is the complete rewriterule, is the first line affecting the rest of the code?


    Code:
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
      RewriteRule ^articles/article/([0-9]+)/(.*)$ articles/article.php?ID=$1 [QSA,L]
        RewriteRule ^articles/articlesfiltered/([A-Z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]

  15. #15
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,244
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Code:
        RewriteRule ^articles/articlesfiltered/([A-Z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
    This will only allow capital letters. That's probably the problem. Try instead [A-Za-z]
    "First make it work. Then make it better."

  16. #16
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cheers dude,

    Thats sorted it.

  17. #17
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    This will only allow capital letters. That's probably the problem. Try instead [A-Za-z]
    Hi,

    Is there anyway this can be tidied up as it creates a major problem. I want to put the name of the product after the unique product ID but it now affects all the links which have a query in.

    Is it possible to isolate only the product line as one which has a second variable after the one I am querying?


    Code:
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    Code:
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
      RewriteRule ^articles/article/([0-9]+)/(.*)$ articles/article.php?ID=$1 [QSA,L]
        RewriteRule ^articles/articlesfiltered/([A-Za-z]+)/(.*)$ articles/articlesfiltered.php?articlecategory=$1 [QSA,L]
      RewriteRule ^plusstyle/plusstyle/([0-9]+)/(.*)$ plusstyle/plusstyle.php?ID=$1 [QSA,L]
       RewriteRule ^plusstyle/plusstylesfiltered/([A-Za-z]+)/(.*)$ plusstyle/plusstylesfiltered.php?articlecategory=$1 [QSA,L]

  18. #18
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Any suggestions please.

    It is only the products/product.php I am looking to add a slug to but it has affected all the links with a query in.

  19. #19
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does anyone have any suggestions on what I can do to fix this? Unfortunately I have messed up my whole site by trying to add the slug into ine set of links.

  20. #20
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is there anything I can try. I really need to get this sorted.


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
  •