Trying to use mod-rewrite for SE friendly urls

I am trying to use this for my mod_rewrite but it is making the links a 404.

RewriteEngine On 
RewriteRule /(.*)/(.*)/$ page.php?category=$1&product=$2

Here is my php

$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `condition`='New' $SQLCat $Limit";
$R_GetEquipment = mysql_query($SQL_GetEquipment, $Link);

if (mysql_num_rows($R_GetEquipment) < $LimitAmt)
$eid = $row['id'];
$itemname = $row['itemname'];
$model = $row['model'];
$manufactuer = $row['manufactuer'];
$desc = $row['desc'];
$imagename = $row['image'];
?>

And the html to echo the info

<a itemprop="url" href="new-product.php?Item=<?php echo $eid; ?>">View Equipment</a>

I have tried to adjust the variables to ty and make it work with the site, I can get the url to show as
new-product.php?Item=My Item Name but of course the link doesnt work.

Any help would be greatly appreciated.

So… i’m gonna say that your href in that link does not appear to match the rewriterule.

What URL are you going FROM, what does the browser say the link is pointing to, and what URL do you end up AT?

(PS: tagging this for moving to the “Server Config” board, as it’s mainly a question about mod_rewrite)

I tried changing the a href to

<a href="new-product.php?Item=<?php echo $itemname; ?>"

Coming from -
new-machinery.php?Cat=CategoryName

Link the browser says - ( when I hover over an item link )
new-product.php?Item=My Item Name

Link I end up at - (when I click on the item )
new-product.php?Item=My%20Item%20Name

and my apologies for posting in the wrong section.

So… your rule is looking for (anything)/Something/Somethingelse/ as your URL.

You’re telling me that your URL is new-product.php?Item=My%20Item%20Name

I… dont see how that rule is supposed to match your pattern?

I am probably not explaining it right.

Rewrite rule I am using

RewriteEngine On 
RewriteRule /(.*)/(.*)/$ page.php?Itemname=$1

Right now I have

new-product.php?Item=203

What I am looking for is

new-product.php?Item=Product-Name

When I do the mod_rewrite I get

new-product.php?Item=My Item Name

But the link (leads to 404 page) is

new-product.php?Item=My%20Item%20Name

My original link

<a itemprop="url" href="new-product.php?Item=<?php echo $eid; ?>">View Equipment</a>

Link edited for mod_rewrite

<a itemprop="url" href="new-product.php?Item=<?php echo $itemname ?>">View Equipment</a>

Hope that made more sense.

And what i’m saying is

/(somethingelse)/(something)/$
says "Take the end of the URL, It must end in a slash. It may have something before that, then another slash, then maybe somethingelse, and before that another slash.

That… is in no way related to the rest of your post - your URL’s have no slashes in them whatsoever…

You’re kind of telling me “I have this rule for a Ford car. I’m having trouble with this Toyota.”

I understand what your saying. I am using it like domain.com/something/something-else/

Thats where I am having the problem, I am not sure how to set up the rewrite rule. I have tried several different variations but always get a 404 when I try to use the item name.

So… why are you doing this with mod_rewrite instead of just… fixing the page.

mod_rewrite generally isnt for changing the parameters of a query string…

Didnt realize the page needs fixed. Whats wrong with it?

So if the desired resullt is to have the product name on the link…put… the product name… on the link? Maybe i’m confused about what you’re attempting to do.

l3,

I usually take great exception to using a trailing / when NOT specifying a directory (it changes the level of the links and is, by Apache standards, incorrect).

I have ALWAYS taken great exception to using the :fire: EVERYTHING (or nothing) :fire: atom as it is greedy and causes too many problems.

My quick scan of this thread left me confused at the problem you’re trying to attack, i.e., what SL was asking for: Pseudo Link and Desired Redirection. Your comments have the redirection creating a query string with Item OR Itemname as the key and it looks like your value is letters (upper and lower) and spaces (which are not acceptable in a URI unless encoded as %20 or, as is the case with the $_GET array, _'s.

My recommendation is two-fold:

  1. Decide what you’re trying to do to the point that it can be specified verbally and

  2. Have a read of the tutorial at http://dk.co.nz/seo which leads you through creating good mod_rewrite code then gives examples for many common uses. If you have questions about that tutorial, drop me a PM and I’ll be glad to clarify.

Finally, mod_rewrite is an extremely useful and powerful tool … when used correctly. Take a few minutes to learn about it and it will serve you well.

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.