简体   繁体   中英

.htaccess - dependancy in rewrite rules

I have the following rewritiing rule for every image URL given within the HTML code

RewriteRule ^([^tn].*\.(gif|jpg|png))$ /media/k2/watermark.php?image=$1&watermark=watermark.png [NC]

I want to add some optional parameter 'partner' that will be injected as a GET parameter to the watermark.php script. But the problem is it won't be added to any of the image URL (cause I don't want to modify every code line that displays an image) but to the website URL. Is it possible to make a dependancy in .htaccess that will work like this:

'If the browser URL has the "partner" parameter inject in into every image URL as well'

Is is possible at all?

Yes it is possible just add QSA (Query String Append) flag to your rule:

RewriteRule ^([^tn].*\.(gif|jpg|png))$ /media/k2/watermark.php?image=$1&watermark=watermark.png [NC,L,QSA]

QSA flag will make sure to keep any browser supplied query parameters while adding new ones from your rewrite rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM