Page 1 of 1

HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 8:27 am
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 ^(blog)($|/) - [L]

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 [QSA]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&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&pagenum=$5 [QSA]

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

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

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

RewriteRule ^robots.txt$ robots.php [QSA]
<a href=\"/type-of-product/$producttype/page/$page/\" class='pagelink'>[Next]</a>

This link isn't working. It opens the page, but it doesn't see it as page 2, it only sees it as Page one.
Even if I put code into the top to see what page it sees, it's always one. I've tried the page line wtih QSA, but it doesn't work.

Re: HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 8:41 am
by Celauran
Take a look at http://htaccess.madewithlove.be/

Reversing the order of your two type-of-product rules should do the trick

Re: HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 8:49 am
by simonmlewis
OH yes. I don't fully understand the QSA and L. And certainly don't understand why changing the order fixes it.

Re: HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 9:18 am
by Celauran
QSA = Query String Append. If you're rewriting /foo/bar?stuff=baz, you need QSA to keep ?stuff=baz after the rewrite.
L = Last. Further rules will not be applied.

The reason the order matters is because of the regular expressions being used. More specific rules need to come first to avoid getting caught by less specific rules. In your case, /type-of-product/foo/page/2 matches
[text]RewriteRule ^type-of-product/([^/]+) /index.php?page=type-of-product&producttype=$1 [QSA][/text]
gets rewritten to /index.php?page=type-of-product&producttype=foo, which then does not match the second rule. Reversing the order means it matches the intended rewrite rule, gets rewritten, and further rewrite attempts are halted due to the L instruction.

Re: HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 9:21 am
by simonmlewis
Gotcha.
So "extra" rules that are part of a basic rule, should come before the basic rule, for that very reason (to avoid it ignore them).

Re: HTACCESS not reading one variable - QSA or L?

Posted: Tue Apr 07, 2015 9:25 am
by Celauran
Yes, precisely. More complex, more specific rules first, broader rules next, catch-all rules last.