I use the following rule to change the path of every image file to .webp. Except for the subdirectories typo3, fileadmin and upload. That works fine.
But the website also loads external images. These URLs shouldnt be changed to .webp
So I added
another condition
<add input="{HTTP_HOST}" pattern="mydomain.com" ignoreCase="true" />
In the rule test interface in IIS it works fine. I use an imagepath from my own domain. The rule test says the pattern fits. If I use an external image path, the pattern did not fit.
BUT if I load a page on my website with different images from different URLs all paths are changed to .webp and this means, that the external ones are not found (404).
How can I make this work?
<rule name="Webp" enabled="true">
<match url="(.+)\.(jpe?g|png)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_ACCEPT}" pattern="image/webp" ignoreCase="false" />
<add input="{HTTP_HOST}" pattern="mydomain.com" />
<add input="{DOCUMENT_ROOT}/{R:0}.webp" matchType="IsFile" />
<add input="{REQUEST_URI}" pattern="typo3/" negate="true" />
<add input="{REQUEST_URI}" pattern="fileadmin/" negate="true" />
<add input="{REQUEST_URI}" pattern="uploads/" negate="true" />
</conditions>
<serverVariables>
<set name="ACCEPTS_WEBP" value="true" />
</serverVariables>
<action type="Rewrite" url="{R:0}.webp" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
<outboundRules rewriteBeforeCache="true">
<rule name="jpg to webp" preCondition="ResponseIsHtml" enabled="true">
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="mydomain.com" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="typo3/" negate="true" />
<add input="{REQUEST_URI}" pattern="fileadmin/" negate="true" />
<add input="{REQUEST_URI}" pattern="uploads/" negate="true" />
</conditions>
I have something new. The external images (and more information) are a response to an AJAX call like this from my own domain.
https://www.example.org:443/index.php?tx_jsdshopware_searchview%5B__referrer%2D%5B%40extension%5D=JsdShopware&tx_jsdshopware_searchview%5B__referrer%5D%5B%40controller%5D=SearchView&tx_jsdshopware_searchview%5B__referrer%5D%5B%40action%5D=list&tx_jsdshopware_searchview%5B__referrer%5D%5Barguments%5D=YTowOnt9af44e2e88d7b23601117be0ff9656fd98a839a38&tx_jsdshopware_searchview%5B__referrer%5D%5B%40request%5D=%7B%22%40extension%22%3A%22JsdShopware%22%2C%22%40controller%22%3A%22SearchView%22%2C%22%40action%22%3A%22list%22%7D2eb573bf2f44341434ca68abb64479da78fd5613&tx_jsdshopware_searchview%5B__trustedProperties%5D=%7B%22searchword%22%3A1%2C%22action%22%3A1%7D0a3b9fd37c893b374a4bb4c2daaa7dd2afa90ccc&tx_jsdshopware_searchview%5Bsearchword%5D=footest&type=4321&tx_jsdshopware_searchview%5Baction%5D=ajaxCall&_=13212131
Can I exclude the rewriting of the filenames my filtering for "ajax" ? I have no experience with these technology.
Related
I have one url which having ./ [period & slash] at the end of parameter. I want to redirect that url with different location but its not even detecting in rules. I am using IIS. I want to configure this on web.config
http://somesitename.com/mypage/teachers-manual./sku/8772
needs to redirect on
http://somesitename.com/mypage/teachers-manual/sku/8772
Though I have tried solution given on Here but its not even working. But if I use same thing instead of Redirect with Rewrite then Rule start working. Not sure why its not working for "Redirect".
<rule name="Trailing Dots and spaces" stopProcessing="true">
<match url="^mypage\/(.*)([\.\s]+)\/(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="/index.cfm/{R:1}/{R:2}/{R:4}" appendQueryString="true" />
</rule>
Actually when I tried to write rule then url which having ./ is also not working.[ http://somesitename.com/mypage/teachers-manual./sku/8772 ]
<rule name="Trailing Dots and spaces1.1" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://somesitename.com/newpage.html" />
</rule>
Not sure where its wrong.
Just got more information on Post & Haacked Said for it.
so I have modified file as follows and now its perfectly working for me.
<configuration>
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Trailing Dots and spaces1.1" stopProcessing="true">
<match url="^(.*)/(.*)\.\/(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}/{R:2}/{R:3}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
.... etc
I need a simple URL rewrite rule for IIS. If the URL doesn't include "/i" after the domain, I would like to add it.
For Example:
If www.abc.com/sample/test.aspx
I need the rule to change it to:
www.abc.com/i/sample/test.aspx
Your rule should be like that:
<rule name="prepend i">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/i/" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/i/{R:0}" />
</rule>
Using URL rewrite and we have lots of old URLs which take the form
/something/else/index.cfm
/this/that/index.cfm
What I would like to do is remove the /index.cfm from these examples
Any ideas?
Thanks
<rule name="Remove Trailing Index.cfm" enabled="true">
<match url="^(.*)/index.cfm" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{R:1}" pattern="category" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}" />
</rule>
How do I rewrite site's base path (i.e. /) using IIS rewrite?
I've tried this so far:
<rule name="RewriteIndexUrl" stopProcessing="true">
<match url="/" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
Currently it's not rewriting that base path, and it's returning the index.html directly.
I could figure out a possible solution and it worked:
Remove all default documents in IIS site (i.e. index.html, index.htm, default.aspx...)
Add the following rewriting rule:
<rule name="RewriteIndexUrl" stopProcessing="true">
<match url="^" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
I've been trying to create user-friendly urls for two of my cfm pages using url rewrite module on IIS 8. That said, there seems to be some sort of conflict due to similarity between rules or something.
Here is what I want to achieve. The following pages:
www.mywebsite.com/news.cfm?category=microsoft
www.mywebsite.com/news.cfm?category=apple
etc
www.mywebsite.com/blog.cfm?title=sometitle
www.mywebsite.com/blog.cfm?title=sometitle
etc
Should look like this:
www.mywebsite.com/news/microsoft
or this
www.mywebsite.com/microsoft
www.mywebsite.com/blog/sometitle
or this
www.mywebsite.com/sometitle
You get the picture.
Here is my code:
<rule name="RedirectUserFriendlyURL4" stopProcessing="true">
<match url="^news\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([^=&]+)$" />
</conditions>
<action type="Redirect" url="news/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL4" stopProcessing="true">
<match url="^news/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="news.cfm?category={R:1}" />
</rule>
<rule name="RedirectUserFriendlyURL5" stopProcessing="true">
<match url="^blog\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="blog/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL5" stopProcessing="true">
<match url="^blog/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="blog.cfm?title={R:1}" />
</rule>
The rules above do not work together and both pages redirect to the one that's set in the first rule. Can this be done with a single rule or do I need to use two? How can I sort this out? I would really appreciate your help on this one. I am using ColdFusion 10 on Windows and IIS 8.