HTACCESS - can you duplicate a line?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

HTACCESS - can you duplicate a line?

Post by simonmlewis »

Code: Select all

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5&h=$6 [L]
This is our product page htaccess for a site we run.
Some folks are trying or found link that don't use the h=$6 on the end, the result is they get an error page.

Is there a simple way to get around this?
ie. Two types of /product pages, that cater for both?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Creating a second rule without the last capture group and without the &h=$6 isn't cutting it?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5&h=$6 [L]
RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5 [L]

We are getting Object Not Found, when we use it without the final /PROD_NAME .
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

And you're certain that's an .htaccess issue? You've tried the query string manually and it returns the desired results?

Also, can you provide some sample links?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

IF the URL is normally:
www.simon.com/product/2/tall/5/red/456/shirt
Then this is what's getting errors:
www.simon.com/product/2/tall/5/red/456

That's it in a nutshell!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Celauran wrote:And you're certain that's an .htaccess issue? You've tried the query string manually and it returns the desired results?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Oh, I see. You didn't remove the last capture group from the regex. What about this?

Code: Select all

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5 [L]
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

Bingo - that was it. Can't believe I missed that!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

Would it caused a problem for me to post a URL like this, and be able to capture the $five variable?

http://site.local/product/80/BUNDLE-OFF ... SET&five=5
This is not using "five" at all. and the HTACCESS is as you suggested it should be. I've tried it with [QSA] as well.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Works fine for me as is. What problem are you encountering?

$_GET:

Code: Select all

Array
(
    [page] => product
    [c] => 80
    [cname] => BUNDLE-OFFERS
    [s] => 44
    [sname] => MONEY-SAVERS
    [menu] => sub
    [product] => 333
    [h] => SPECIAL-410-SET
    [five] => 5
)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

When sent, this is the code I am running, and it worked fine but since something I have changed, it now stops.

Code: Select all

$five = isset($_GET['five']) ? $_GET['five'] : null;
if (isset($five))
{
if ($five == "3" || $five == "4" || $five == "5")
{
 $counter = 0;
    while ($counter < $five)
      {
      mysql_query ("INSERT INTO rating (prodid, stars) VALUES ('$myprod', '$five')");
      $counter = $counter + 1;
      }
mysql_query ("UPDATE products SET staroverride = '$five' WHERE id = '$myprod'");
}
Even if I just put it like this:

Code: Select all

$five = isset($_GET['five']) ? $_GET['five'] : null;
if (isset($five))
{
echo "hi there";
}
Nothing comes up.
It simply doesn't nothing "extra" on screen.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

It doesn't matter what I use - if I capture $fred, and then echo that, it won't echo it, so for some reason it won't let me put anything oni the end of the url.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Have you checked the contents of $_GET? What other scripts does it go through before arriving at the above? Have you checked those as well?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

Sorry to be dumb, but how do I see what is in $_GET? I can understand your thinking and I reckon you could be right. Though "$five" is not used elsewhere.
IS it just $test = $_GET;??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - can you duplicate a line?

Post by Celauran »

Either of these will work.

Code: Select all

var_dump($_GET);

Code: Select all

print_r($_GET);
You might want to wrap it in <pre> tags, and maybe call exit afterward to stop execution from continuing. Really, you ought to be using something like XDebug, but that's for another time.
Post Reply