I am trying to hide a subdirectory where I installed a framework. While this works like a charm in .htaccess, I am getting stuck with IIS rules. Basically I want to go from
http://www.mysite.com/CI/client-tracking to
http://www.mysite.com/client-tracking
I am using this rule
<rule name="Redirect to Codeigniter" stopProcessing="true">
<match url="^client-tracking$" ignoreCase="false" />
<action type="Rewrite" url="/CI/client-tracking" />
</rule>
LE: I am not in need of a redirect, I need to rewrite the URL and eliminate the \CI directory from it, so the user and search engines see a nice link.
Did you try removing the leading "/" on the re-written url
<rule name="Redirect to Codeigniter" stopProcessing="true">
<match url="^client-tracking$" ignoreCase="false" />
<action type="Rewrite" url="CI/client-tracking" />
</rule>
Related
I am struggling getting an IIS rewrite rule working.
The old urls look like:
https://wwww.testserver.com/package.aspx?TrackingNumber=number
The new web app is expecting the urls in this format:
https://wwww.testserver.com/package/number
Currently I have the following rule setup, which is not working.
<rule name="Rewrite to new Package site" stopProcessing="true">
<match url="^package\.aspx\?TrackingNumber=([_0-9a-z-]+)" />
<action type="Redirect" url="https://www.testserver.com/package/{R:1}" logRewrittenUrl="true" />
</rule>
The interesting part is, if I remove package.aspx\? from the rule, urls like these https://wwww.testserver.com/oldwebsite/TrackingNumber=number are getting matched.
In my test calls I replaced package.aspx with package.html and these urls are not getting matched as well. It looks like IIS ignores urls with filenames in the url.
You could use below url rewrite rule to redirect https://wwww.testserver.com/package.aspx?TrackingNumber=number to https://wwww.testserver.com/package/number:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="package(.aspx)" />
<add input="{QUERY_STRING}" pattern="TrackingNumber=(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:2568/package/{C:1}" appendQueryString="false" />
</rule>
Note: You could modify hostname as per your requirement.
Regards,
Jalpa
I have website with multiple domains and i want them to have different robots.txt
I have rule for this so depends on domain request it will return different robots. This is workin beta slot but after deploy to production slot its not working.
<rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^robots.txt" />
</conditions>
<action type="Rewrite" url="https://{HTTP_HOST}/{HTTP_HOST}.robots.txt" />
</rule>
If i am changing action type to redirect it seems to work because webbrowser redirects and is in stuck with to many redirects (Which make sense.)
As url-rewrite-module-configuration-reference mentioned that the server variable REQUEST_URI can be used to access the entire requested URL path, including the query string. Assuming that the URL for robots.txt is https://<your-hostname-and-port>/robots.txt, then you would get the string /robots.txt as an input via REQUEST_URI.
<rewrite>
<rules>
<rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/robots.txt" />
</conditions>
<action type="Rewrite" url="{HTTP_HOST}.robots.txt"/>
</rule>
</rules>
</rewrite>
With the rule above, I could rewrite my URL and get the following result:
Changing the type of the rule action from Rewrite to Redirect, I could get the following result:
I need to create easy to remember URL's that redirect to long and hard to remember paths for a large number of applications.
i.e.
subdomain.domain.edu/shortname
redirects to
https://www.subdomain.domain.edu/mainApplication/subfolder/page
I'm using the URL Rewrite module in IIS 8.5, but I keep getting a 404 when I browse to the short alias. I know the rewrite module is working as I use it to handle rewriting HTTP to HTTPS and to add WWW to a URL.
My rewrite rule looks like:
<rewrite>
<rules>
<rule name="Easy to remember shortcut" stopProcessing="true">
<match url=".*subdomain.domain.edu/shortname" />
<conditions>
<add input="{URL}" pattern=".*/shortname" />
</conditions>
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page.aspx" />
</rule>
</rules>
</rewrite>
Of course this returns a 404. Any ideas?
Forgive me if there is already an answer to this in another post, however, I've read through and tried over 30 posts on the URL rewrite module and have not yet found the solution for actually creating an alias.
Url rewrite match condition won't be able to see your domain i.e. if the URL is https://www.subdomain.domain.edu/shortname the match part can only see shortname (anything after domainname/).
To validate the host we need to add in the conditions clause. So your rule will be something like below
<rule name="shortnameURL" enabled="true" stopProcessing="true">
<match url="shortname" />
<action type="Redirect" url="mainApplication/subfolder/page" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*subdomain.domain.edu" />
</conditions>
</rule>
Also it should be ok if you add the entire URL here
<action type="Redirect" url="mainApplication/subfolder/page" /> as below
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page" />
I've seen several blogs and questions which I believe match what I'm doing, but it's not working. URL Rewrite module is installed. I'm resetting IIS after I save this web.config file. I've tried using IIS's GUI as well with same results. Is there something else I'm not aware of?
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.us$" />
</conditions>
<action type="Redirect" url="http://www.domain.us/{R:0}" />
</rule>
</rules>
</rewrite>
Ok, I forgot to add the binding domain.us to the site. Woops!
I am trying to get the IIS7 URL Rewrite module working with Sitecore. I imported some rules and successfully tested them, but when I attempt to go to a URL I've setup a redirect for I get the Sitecore 404 page instead. So it's as if Sitecore is intercepting the page request before the URL Rewrite module has a chance to.
Sample rule:
<rule name="Imported Rule 1">
<match url="/pastsub(.*)" ignoreCase="false" />
<action type="Redirect" url="http://www.domain.net" redirectType="Found" />
</rule>
Any ideas on how to fix this?
Adding stopProcessing="true" to the rule will probably solve your problem:
<rule name="Imported Rule 1" stopProcessing="true">
<match url="/pastsub(.*)" ignoreCase="false" />
<action type="Redirect" url="http://www.domain.net" redirectType="Found" />
</rule>