nats nats - 9 days ago 5
PHP Question

Append extra get variable to URL via .htaccess

I am trying to append an extra

get
variable onto a URL. I'm currently using OpenCart with a custom theme I bought. However, the developers of the theme have been unresponsive.

When I search for a product, it only searches the title. There is a checkbox to search the descriptions, but this is set to "off" by default, and I cannot find anywhere in the code to append or change this to the URL. It's a matter of adding
&description=true
to the end of the URL.

I have:

index.php?route=product/search&search=123


...and I need to append the description to this, to make it look like:

index.php?route=product/search&search=123&description=true


My last resort is to modify the .htaccess, so I can hijack the search request, per say, and amend this to the end.

I have tried writing some, but to no avail.

RewriteRule ^/page /page?var=val [QSA]


I just cannot seem to fiqure out how I need to write this, in order for it to work. Could some one please point me in the right direction?

EDIT - Still messing round and now I have:

RewriteRule index.php?route=product/search&search=(.*) /index.php?route=product/search&search=$1&description=true [QSA]


It won't append it to the original, but when I add
&description=true
manually, it adds another one? So it becomes:

index.php?route=product/search&search=123&description=true&description=true

Answer

You cannot match query string in RewriteRule. Use RewriteCond like this:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^route=product/search&search=[^&]+$ [NC]
RewriteRule ^index\.php$ /$0?description=true [QSA,L,NC,NE,R=302]
Comments