This gives a 404 not found:
<rewrite url="~/forum/viewforum.php?f=([0-9]+)" to="~/Handlers/PermRedirect.ashx?ID=$1&action=forumcat" processing="stop"/>
But this works:
<rewrite url="~/forum/viewforum.php" to="~/Handlers/PermRedirect.ashx?ID=5&action=forumcat" processing="stop"/>
Am I handling this wrong? I'm just trying to pass the querystring data from the original url to the redirect script.
seems that you forgot the "\" escape character for "?". Give a try this.
<rewrite url="~/forum/viewforum.php\?f=([0-9]+)" to="~/Handlers/PermRedirect.ashx?ID=$1&action=forumcat" processing="stop"/>
Maybe something here will help:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Related
I have a wordpress site and has template page. I am passing class ID as cid parameter. http://www.example.com/class-details/?cid=51
I want it to have like http://www.example.com/class-details/
I wrote rule below in .htaccess
RewriteRule ^class-details/?([^/]*)$ example.com/class-details/$1 [NC,R,L]
It leads to recursive redirection. I tried checking wordpress redirect API a lot. but no luck. Please guide me for this.
Better to create custom post type, then you don't need to pass the cid or anything and you will have Rewrite URL.
try this
<rule enabled="true" match-type="wildcard">
<from casesensitive="true">/class-details/cid=([a-zA-Z0-9]+)$</from>
<to type="passthrough">/class-details?cid=$1</to>
</rule>
I use UrlMappings in web.config. Now, I must have 2 url entries to make the mapping work with both the trailing backslash and without. Like this:
<urlMappings>
<clear />
<add url="~/app" mappedUrl="~/Templates/Sections/Common/Article.aspx?id=981" />
<add url="~/app/" mappedUrl="~/Templates/Sections/Common/Article.aspx?id=981" />
</urlMappings>
Is it possible to make the url (~/app) work with or without trailing slash, in one line of code? Mabye by using wildcard or something for the "~/app" url..?
The urlMappings element doesn't allow for wildcards or regular expressions. A better solution for this problem would be the fully featured URL Rewrite Module (which is an optional module you can install in IIS) which do indeed allow you to write regex's to map your incoming URLs to an internal path.
We are trying to rewrite like domainname.com/cityname. However this not resolving to the respective page. But when we try something like this domainname.com/city/cityname it works well and resolve to the correct/designated url
This is the code in webconfig
<rewriter>
<rewrite url="~/city/(.+)" to="~/Default.aspx?propid=$1" processing="stop"/>
</rewriter>
How to redirect to the page by giving domainname.com/cityname
Thanks in advance
try
<rewriter>
<rewrite url="/(.+)" to="/Default.aspx?propid=$1" processing="stop"/>
</rewriter>
where $1 is the fraction after / in the url
so
something.com/name_of_city
will redirect to
something.com/Default.aspx?propid=name_of_city
I have:
<!-- Force lowercase URLS -->
<rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />
Perm redirect simply 301 redirects to the new URL.
This rule is meant to redirect any URL with an uppercase char to the lower case one.
This however creates a redirect loop, any ideas why? The only rules running so far are:
<rewriter>
<!-- Remove Trailing Slash for all URLS-->
<rewrite url="~/(.*)/($|\?(.*))" to="~/handlers/permredirect.ashx?URL=${lower($1)}$2" />
<!-- Force lowercase-->
<rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />
<rewrite url="~/construct2($|\?(.*))" to="~/construct2.aspx" processing="stop" />
</rewriter>
You can either modify the regular expression to exclude .ashx files (which might get extremely complicated) or create a new rule before this rule, that will catch URLs pointing to ashx files and redirect them to a lowercase version of the string.
Something like this might work (not tested):
<rewrite url="~/(?=(.*\.ashx.*))(.*[A-Z]+.*)" to="~/${lower($1)}" />
It uses a lookahead rule to check if ".ashx" is part of the url and if the URL is uppercase. If yes, it redirects to the lowercase version of the same url.
I am using urlrewriter.net and I am trying to make a redirection. So here is the condition,
If the requested url doesn't end with a / (slash) and
then add / at the end of the url and
redirect to added url.
So if the url is "http://www.something.com/cases" then add / and redirect it to "http://www.something.com/cases/"
I've used code but it didn't work out for me :
<if url="^~/(.+)(/){0}$">
<redirect url="~/(.+)" to="~/$1/$"/>
</if>
I am going to answer my own question here :
I've accomplished this by using this way :
<unless url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.aspx|\.ashx|\.ascx|\.shtml|\.html|\.htm)(\?.+)?)$">
<if url=".+(?<!/)$">
<redirect url="(.+)" to="$1/"/>
</if>
</unless>
If url doesn't end with "/" then it will be redirected to the one which has "/" at the end.
I hope it helps everyone out there.
Can you use the URL Rewrite 2.0 module? You can easily add it there, because the rewrite template for that rule is a built-into the GUI.