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:

Re: HTACCESS - can you duplicate a line?

Post by simonmlewis »

Ok I do have GETs there, but only becuase of the URL.
Nothing for $five.
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 »

Oh and if I put "test=2" on the end of the URL, it does not show up in the array.

With this at the start:
[text]array(7) [/text]
Surely ther should be 8!? if I have an eight on the end.
Last edited by simonmlewis on Tue Oct 07, 2014 9:44 am, edited 1 time in total.
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 that's even with QSA in the RewriteRule? Where did you check for it (ie. where in the execution)?
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 »

Yes, with QSA. And it's just before the execution of the $five script.
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 »

What about at the very beginning of index.php, before anything else executes?
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 I put it literally after session_start:

Code: Select all

<?php session_start();
$five = isset($_REQUEST['five']) ? $_REQUEST['five'] : null;
if (isset($five)) { echo "<font color='#ff0000'>hi</font>";}
Still nothing echoes on screen.
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 »

Let's see your .htaccess, then.
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 »

Code: Select all

DirectoryIndex index.php index.html index.htm
order allow,deny
allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^error/?$  /selectpage [QSA]

RewriteRule ^(blog)($|/) - [QSA]

RewriteRule ^knowledge/([0-9]+) /index.php?page=knowledge&id=$1 [QSA]
RewriteRule ^knowledge/answer/([0-9]+)/([0-9]+) /index.php?page=knowledge&id=$1&id_link=$2 [QSA]

RewriteRule ^pricedrop/page/([0-9]+)/ /index.php?page=pricedrop&pagenum=$1 [QSA]
RewriteRule ^productsnew/page/([0-9]+)/ /index.php?page=productsnew&pagenum=$1 [QSA]

RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [QSA]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&menu=sub&pagenum=$3 [QSA]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [QSA]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub&pagenum=$5 [QSA]

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&menu=sub&product=$5 [QSA]
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 [QSA]

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

RewriteRule ^type/([^/]+) /index.php?page=type&type=$1 [QSA]
RewriteRule ^use/([^/]+) /index.php?page=use&use=$1 [QSA]

RewriteRule ^romancode/([^/]+) /index.php?page=romancode&romancode=$1 [QSA]
RewriteRule ^productsall/([0-9]+)/ /index.php?page=productsall/ [QSA]

RewriteRule ^productsall/page/([0-9]+)/ /index.php?page=productsall&pagenum=$1/ [QSA]
RewriteRule ^manufacturers/([^/]+) /index.php?page=manufacturers&manufacturer=$1 [QSA]

RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [QSA]

RewriteRule ^$ index.php?page=home [QSA]

RewriteRule ^robots.txt$ robots.php [QSA]
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 if you reverse the order of these two rules?

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 [QSA]
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 [QSA]
The more specific rule should come first.
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 »

Well damn me, it worked.
Why would that cause it to not work then in the other order?
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 »

Because it was matching the less specific rule first and rewriting the request like you asked it to.
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 »

Here is a simple problem with URLs and potentially HTACCESS.
$power is set to "electric".

Code: Select all

<a href=\"/power/page/$power/$page/\" class='pagelink'>[Next]</a>

Code: Select all

RewriteRule ^power/([^/]+) /index.php?page=power&power=$1 [QSA]
RewriteRule ^power/page/([0-9]+)/([^/]+) /index.php?page=power&pagenum=$1&power=$2 [QSA]
When it opens, and on the first pages it's just:
/power/$power.
such as ".../power/electric".

When I hover over the [next] link it shows /power/page/electric/2/.
But when the page turns over, it replaces the content of $power" with the word "page".
Doing the _GET dump, I get this:
[text]array(2) { ["page"]=> string(5) "power" ["power"]=> string(4) "page" } Array ( [page] => power [power] => page ) page, 1[/text]

I've no idea why. We use this style for categories and other pages. If I remove the second rewriterule, oddly we get no errors, and the same problem.
So maybe it is just ignoring the rule? Same happens if I switch the order of the rules.
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 if you switch the order and change [QSA] to [L,QSA]?
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 - what is L,QSA then?
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 »

L is 'last', QSA is 'query string append'

http://httpd.apache.org/docs/2.2/mod/mo ... ewriterule
Post Reply