nats nats - 1 year ago 49
PHP Question

Append extra get variable to URL via .htaccess

I am trying to append an extra

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
to the end of the URL.

I have:


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


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
manually, it adds another one? So it becomes:


Answer Source

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]