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?


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…

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>

<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>

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?

Affirmative,

That is the latest htaccess file.

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

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.

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?

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

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.

I’m presuming that you found and removed some other htaccess file? Where did that file live and what was in it?

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.

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

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…


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.



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

Hi,

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

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.

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.

This is the complete rewriterule, is the first line affecting the rest of the 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]

This will only allow capital letters. That’s probably the problem. Try instead [A-Za-z]

Cheers dude,

Thats sorted it.

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?

  RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]

  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]

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.

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.

Hi,

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