ty_ger07
Insert Custom Title Here
- Total Posts : 16602
- Reward points : 0
- Joined: 4/11/2008
- Location: traveler
- Status: offline
- Ribbons : 271

I posted this over on StackOverflow but have not yet received a response. Perhaps someone here knows the answer. http://stackoverflow.com/...orming-an-htaccess-uri I have published some webpage code on GitHub and it is used by quite a few people without issue. But, just recently, a person contacted me to let me know that they are having an issue with an image not displaying properly. The image is generated by a php file and I am using an .htaccess rewrite to refer to the file as .png in URLs but process internally on the web server as .php.
It is my understanding that an apache server should include the original query string in the URI rewrite by default, but this person's web server is not doing such. This is the first person who has reported the issue and I have not been able to duplicate the issue on the web servers I have tested. I am not sure of this person's web server environment.
This is the incorrect image output which the user is reporting:
 https://freiezocker-clan....image-banner.png?sid=1
The result returned in the image above says that a server id is required. The sid is in the query string but is being ignored. On other web servers, it has worked fine.
This is what the image output should look like (when avoiding the .htaccess rewrite):
 https://freiezocker-clan....image-banner.php?sid=1
This was my .htaccess implementation before the user reported the issue:
RewriteEngine on RewriteRule ^(.*)\.png $1.php [NC]
This was my attempt to fix (without success) the reported issue:
RewriteEngine on RewriteRule ^(.*)\.png $1.php?%{QUERY_STRING} [QSA,NC,L]
Could you please explain to me why that user's web server is not including the query string and/or could you please help me implement a change which will correct the issue for that user?
Thank you!
post edited by ty_ger07 - Friday, April 14, 2017 2:11 AM
ASRock Z77 • Intel Core i7 3770K • EVGA GTX 1080 • Samsung 850 Pro • Seasonic PRIME 600W Titanium
|
James_L
CLASSIFIED Member
- Total Posts : 4336
- Reward points : 0
- Joined: 7/29/2009
- Status: offline
- Ribbons : 46

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, April 16, 2017 3:24 PM
(permalink)
Since it's a single user and you're not able to replicate the issue on your installations/troubleshooting I would tend to think that their Apache server is misconfigured in some way. Either their .htaccess is too restrictive for remote rewrites or something else. I'll take a look at your project and see what, if anything, I can see that may be an issue. From the looks of things, especially when I head on over to your links provided above, all appears to be correct. I'll see if I can replicate the person's issue, if possible, and if so see if I can help remediate.
|
James_L
CLASSIFIED Member
- Total Posts : 4336
- Reward points : 0
- Joined: 7/29/2009
- Status: offline
- Ribbons : 46

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, April 16, 2017 3:38 PM
(permalink)
ty_ger07
This was my attempt to fix (without success) the reported issue:
RewriteEngine on RewriteRule ^(.*)\.png $1.php?%{QUERY_STRING} [QSA,NC,L]
(Seems that I needed to look further into this before I had come up with the following which may have corrected it...)First it is my understanding that if you decide to use the {QUERY_STRING} variable you need to set conditions as to what you are matching in your .htaccess for redirects. The query string is not part of the match in the rewrite rule. I would expect that it is meant for a particular set of conditionals, such as:
RewriteCond %{QUERY_STRING} ^who=a$
RewriteRule ^people.php$ /people/?t=leadership [R=301,L]
Notice it checks for a conditional prior to the rewrite rule being implemented in the above example. I think your original (working) rewrite rule would be better suited as you're passing a variable to it and you aren't looking to redirect based on particular conditions, just a particular SID which would be contained elsewhere that the php script would evaluate after being passed. [edit] Looks like you may be adding additional flags which may need to be taken into consideration. While your original statement should be perfectly fine in sending the variables to your query process, there might be a better way to do it though it may need some tweaks. The revised rewrite rule would be most likely better suited not using the QSA flag as it's going to append the entire query string to the end of the request. It would be (probably) better suited to using the following line instead.
RewriteEngine on RewriteRule ^(.*)\.png $1.php?%{QUERY_STRING}
This way it can pass the query string being sent to the variable without needing to use the QSA which would combine the original string along with the query string as a URL. This is most likely not what you are looking to have done. The NC flag is fine if you don't care about case for the query and will allow for any type to be send into your query. The L flag is ok for termination though, since you don't have conditionals, it doesn't necessarily need to be there as there aren't any conditional statements to avoid.  [/edit]
post edited by James_L - Sunday, April 16, 2017 3:49 PM

|
James_L
CLASSIFIED Member
- Total Posts : 4336
- Reward points : 0
- Joined: 7/29/2009
- Status: offline
- Ribbons : 46

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, April 16, 2017 4:00 PM
(permalink)
Oh and one of the mods may want to move this to 'General Software' as it's appropriate for that forum. I doubt it needs to reside here.
|
ty_ger07
Insert Custom Title Here
- Total Posts : 16602
- Reward points : 0
- Joined: 4/11/2008
- Location: traveler
- Status: offline
- Ribbons : 271

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, April 16, 2017 9:15 PM
(permalink)
Thanks a lot for the help! I will give it a try! If nothing else, it's an improvement and sanity check.
ASRock Z77 • Intel Core i7 3770K • EVGA GTX 1080 • Samsung 850 Pro • Seasonic PRIME 600W Titanium
|
James_L
CLASSIFIED Member
- Total Posts : 4336
- Reward points : 0
- Joined: 7/29/2009
- Status: offline
- Ribbons : 46

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, April 16, 2017 10:02 PM
(permalink)
ty_ger07 Thanks a lot for the help! I will give it a try! If nothing else, it's an improvement and sanity check.
It's always good to get a second set of eyes on anything. Especially when you're looking into regex conditionals in Apache. They can be very cryptic and confusing a lot of the time. I haven't been able to recreate the issue on my CentOS 6/7 servers using apache 2.x at all. The rewrite rule with variable passing works just fine when I pass it to a test machine. I think the user who was having an issue may have misconfigured their system and it's not processing it appropriately. Perhaps they may need to show what modules they have activated and/or any other customized configurations they have going which may cause it to ignore the variable being passed.
|
ty_ger07
Insert Custom Title Here
- Total Posts : 16602
- Reward points : 0
- Joined: 4/11/2008
- Location: traveler
- Status: offline
- Ribbons : 271

Re: web server is not including the query string when performing an .htaccess URI rewrite
Thursday, April 20, 2017 11:29 PM
(permalink)
To bring this strange tale (almost no one cares about) to a close: http://stackoverflow.com/a/43527857/7859358 The server host has determined that their web server is chopping off the query string because the extension is PNG and it is abnormal for a PNG image to have a query string. I agree that it is abnormal for a PNG image to have a query string, but it was necessary for the extension to be PNG and it was necessary for the URL to include additional information (and thus I chose to use a query string). The odd thing is that it has worked fine for so many people on so many different web servers until now. That being said, I will have to rethink my webpage code to include the additional information into the file name in the URL and extract it from there. https://forum.myrcon.com/showthread.php?6854&p=139120&viewfull=1#post139120
ASRock Z77 • Intel Core i7 3770K • EVGA GTX 1080 • Samsung 850 Pro • Seasonic PRIME 600W Titanium
|
vampiresinc
New Member
- Total Posts : 100
- Reward points : 0
- Joined: 6/1/2008
- Status: offline
- Ribbons : 0
Re: web server is not including the query string when performing an .htaccess URI rewrite
Friday, May 05, 2017 3:09 AM
(permalink)
that is either a setting restriction your host is putting on it and if so I would move hosts or something configured in apache/php.ini. that is not normal it shouldn't care if you have a query string on a link. I can try to dig into it more since I'm not at my server right now to see if there is a setting in either of those.
|
ty_ger07
Insert Custom Title Here
- Total Posts : 16602
- Reward points : 0
- Joined: 4/11/2008
- Location: traveler
- Status: offline
- Ribbons : 271

Re: web server is not including the query string when performing an .htaccess URI rewrite
Saturday, May 13, 2017 7:26 PM
(permalink)
It isn't my host. It is someone else who came to me for help. I agree that it is that person's server host who has added a restriction (probably a global URI rewrite of their own) which drops the query string from all URLs which don't end in specific extensions. Probably something they decided to do in the name of some false sense of security. This is my solution to the above problem: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)(pid)(.*\d)(fav)(.*\d)(.*) $1.php?$2=$3&$4=$5 [QSA,NC,L] RewriteRule ^(.*)\.png $1.php [NC] The result is this: Example 1 (same as before): Input (URI) file name: signature. png?pid=7&fav=0 Output (server parsed) file name: signature. php?pid=7&fav=0 Example 2 (updated option for this user): Input (URI) file name: signature pid7fav0. pngOutput (server parsed) file name: signature. php? pid=7&fav=0 It keeps the old method working and allows the new method -- for this person with a weird host -- to work.
post edited by ty_ger07 - Saturday, May 13, 2017 7:42 PM
ASRock Z77 • Intel Core i7 3770K • EVGA GTX 1080 • Samsung 850 Pro • Seasonic PRIME 600W Titanium
|
James_L
CLASSIFIED Member
- Total Posts : 4336
- Reward points : 0
- Joined: 7/29/2009
- Status: offline
- Ribbons : 46

Re: web server is not including the query string when performing an .htaccess URI rewrite
Sunday, May 14, 2017 0:32 PM
(permalink)
In getting back to this a bit, since I was involved, it seems that the provider just isn't admitting that they have a rewrite rule already in place for that and you're having to work around with your secondary code just to satisfy a single user. Pity they just didn't specify that in the first place so you could have put in the option for the additional rewrite string into your code to account for it, instead of telling you that you were using a depreciated set of options, even though it's not depreciated. At least you have taken care of (for now) the trouble.
|