Rewrite rule for special character/encoded url - .htaccess

I'm new to Dotnet and I need redirect below url to home page for SEO. In browser, encode url is changing to html tag and rewrite url is not working. Please help me to fix this.
Example: domain.com/xyz-%3Cb%3Eabc%3C/b%3Eurl
I tried below Rule. Please let me know what i'm doing wrong.
<rule name="Redirect" stopProcessing="false">
<match url="^xyz-%3Cb%3Eabc%3C/b%3Eurl$" />
<action type="Redirect" url="/" appendQueryString="false" redirectType="Permanent" />
</rule>

Related

IIS and URL Rewrite for landing pages and simple URLs

Right now we have a bunch of extra directories with an index.htm in them that handle redirects to pages within our application. Instead of littering our folder structure with these, is there a way to us URL rewrite to redirect a user without completely breaking 404 errors?
For example,
domain.com/login
Would redirect to
domain.com/user/accountLogin.htm
Or
domain.com/happypartnercompany
Could go to
domain.com/partners/about.xyz?partner=123
For anyone else looking for a simple example, this is what I ended up doing:
<rule name="members" stopProcessing="true">
<match url="^members*$" ignoreCase="true" />
<action type="Rewrite" url="index.xyz?m=home/members/list" />
</rule>
And to actually redirect the user:
<rule name="member_signup_1" stopProcessing="true">
<match url="^sefcu*$" ignoreCase="true" />
<action type="Redirect" url="index.xyz?m=signup/enroll&partnerid=8532" />
</rule>
Ampersands must be escaped with & in the URL.

URL Alias in IIS 8.5 Using URL Rewrite Module

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" />

Remove a part of url with rewrite

I'm not familiarized with this feature and I've found some examples how to do something but I don't know how to set this case:
I want this url http://www.domain.co.uk/anything/en to become http://www.domain.co.uk/anything/
I want to remove the final 'en'
I've tried with:
^/([_0-9a-z-]+)/([_0-9a-z-]+)/en
/{R:1}/{R:2}
or
^http://www.domain.co.uk/([_0-9a-z-]+)/(en)
http://www.domain.co.uk/{R:1}/
But it doesn't work.
You can use the following rule:
<rule name="Remove en" stopProcessing="true">
<match url="^(.*)/en$" />
<action type="Rewrite" url="{R:1}" />
</rule>
It will match any url ending with /en and remove this part.
From your example, http://www.domain.co.uk/anything/en will be rewritten as http://www.domain.co.uk/anything
If you want the user to be redirected, then use the following rule:
<rule name="Remove en" stopProcessing="true">
<match url="^(.*)/en$" />
<action type="Redirect" url="{R:1}" />
</rule>
The type="Redirect" with no option triggers a permanent(301) redirect.

How to redirect old directory to new one on IIS

I want to redirect an old directory to the new one (301 redirection). In my case i want this :
http://www.mydomain.com/xxxx/ redirect to http://www.mydomain.com/yyyy/
http://www.mydomain.com/xxxx/1-my-product-name redirect to http://www.mydomain.com/yyyy/1-my-product-name
http://www.mydomain.com/xxxx/c/my-category-name redirect to http://www.mydomain.com/yyyy/c/my-category-name
etc...
To do this, I use the URL Rewriting module on IIS to do this. This is my rule in my web.config :
<rule name="test" stopProcessing="true">
<match url="xxxx" />
<action type="Redirect" url="yyyy{R:0}" appendQueryString="true" />
</rule>
It works fine with http://www.mydomain.com/xxxx/1-my-product-name and http://www.mydomain.com/xxxx/c/my-category-name but when i go to http://www.mydomain.com/xxxx/ it's redirect to http://www.mydomain.com/yyyy// with two slahes. Anyone know how to avoid this ?
Thanks in advance !
I found, this is the rule that i used :
<rule name="tpepme" stopProcessing="true">
<match url="xxxx(.*)" />
<action type="Redirect" url="yyyy{R:1}" appendQueryString="true" />
</rule>

Sitecore not respecting II7 URL Rewrite module

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>

Resources