Reputation: 31
There has been a migration from a apache server to IIS, the base transfer was pretty easy and it is running, but I've got a rather annoying issue that I would like to solve.
The issue: They are using zii 'cgridview' to show their tables; while it's not a pretty solution (might be the implementation), it worked fine for Apache.
The pagination itself works fine but when they are filtering it; it will do a 'GET' to get all the information, this sort of works for the first time but when we paginate to another page it suddenly go haywire (because it's a GET).
The issue here is it will do a request with all the filters, so it's like:
https://example.com/controller/action/filter1/value/filter2//filter3//filter4/hallo
This is normally the correct format how it should work (with apache rewrite at least), however IIS does not seem to like this, in my opinion why?
If you like closer we got a filter1 and the next parameter is a value; filter2 does not have a value so it's empty and there now two 'slashes' (between those slashes is nothing; so it's empty) but as far I can imagine IIS is trimming those slashes away so it's a single slash.
Filter for filter1 works as expected; but filter2 will have filter3 as value; which is not correct. Does anyone have an idea what can cause this issue?
The rewrite is like this:
<rule name="yii_rewrite" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
Thank you for your time, appreciate it!
Upvotes: 0
Views: 413
Reputation: 31
As far I am aware the problem is caused because the 'REQUEST_URI' is encoded by default, double slashes are turned to single slashes. In order to resolve this issue; we can replace the REQUEST_URI with UNENCODED_URL; that way the double slashes remains.
This works but IIS must have had their reasons for that; it's better to fix it in code and not putting a band aid on it. If this can cause issues; I would love to hear about it - preferably I would like to resolve this cleanly even though this is old code that will stop at the end of the year.
<serverVariables>
<set name="REQUEST_URI" value="{UNENCODED_URL}" />
</serverVariables>
Upvotes: 0
Reputation: 22144
I suggest to disable this behavior completely by settings CUrlManager::$appendParams
to false
. As a result you should get URLs like https://example.com/controller/action?filter1=value&filter2=&filter3=&filter4=hallo
, which should be less confusing not create any problems.
Upvotes: 0
Reputation: 7522
At present, these double slashes will be processed by the modern IIS/Apache webserver. Only some old browsers will convert the double slashes to another meaning. thereby, we could add URL Rewrite
rules in IIS/Apache server to remove the extra slash, just like below.
mod_rewrite
in Apache.
# remove multiple slashes anywhere in url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
Equally, in the IIS URL Rewrite module.
<rewrite>
<rules>
<rule name="Imported Rule" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<!--# remove multiple slashes anywhere in url -->
<add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
</rule>
</rules>
</rewrite>
Please refer to the below link for more details.
https://webmasters.stackexchange.com/questions/8354/what-does-the-double-slash-mean-in-urls/8381#8381
Upvotes: 0