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
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>
Currently working with an external file for URL rewrites called rewritemaps.config (following these instructions), which works great. However, we have occasion to override an entry in that file with manual entries in web.config instead and they don't appear to work.
Specifically this issue has cropped up around the use of content experiments (A/B testing) with Google, which makes heavy use of querystrings in my URLs. The querystring takes the form of:
websiteurl.com/webpage1?utm_expid=########-#&utm_referrer=http%3A%2F%2Fwebsiteurl.com%2F
Now when attempting to validate my content experiment, I get the error
Web server rejects utm_expid. Your server doesn't support added query
arguments in URLs.
...which is true for that particular URL because in the rewritemaps.config file we have this line:
<add key="/webpage1" value="/somefolder/file.aspx?id=18" />
The rewrite rule works fine but no amount of manual entries in web.config seem to work. If I comment out the line in rewritemaps.config and attempt to reach /webpage1, it errors with 404..which is expected. But I try to use manual entries in my web.config like:
<rule name="test rewrite" stopProcessing="true">
<match url="^(https?:\/\/)?websiteurl.com\/webpage1(.*)*" />
<action type="Rewrite" url="{R:1}/somefolder/file.aspx?id=18" appendQueryString="false" />
</rule>
I'm placing the rewrite rule before
<rewriteMaps configSource="rewritemaps.config" />
I've added query_string conditions, appendQueryString to true and to false, nothing is working even if I use wildcard patternSyntax, so it's leading me to believe that I can't manually add rewrite rules into the web.config if there is an external rewritemaps.config file.
Is this true? If so, how can I manually override a rewrite rule because I have to add the ability to allow a querystring in a rewrite?
Well after much consternation and research, I stumbled upon this question and the highest voted answer, and it's working for me now with the rewrite rule still in rewritemaps.config.
Changing {REQUEST_URI} to {PATH_INFO}
I am trying to redirect all non existent pages to a different domain, as my blog was moved to a different domain.
So www.mydomain.com/blog/asdf should redirect to blog.mydomain.com/blog/asdf
Using Intelligencia URLRewriter module I can redirect blog/ but if I do blog/something I get a 404.
Even with a simple rule without regex like this one, it doesn't work for anything under the blog folder
<rewrite url="~/blog/^" to="http://blog.softwaresynergy.com/blog/" />
I also tried this to force all requests to go to the handler
<modules runAllManagedModulesForAllRequests="true">
Any ideas on how to pick up everything under blog/ and redirect to the other domain?
Try with following redirect rule:
<redirect url="^/blog/(.+)$" to="http://blog.softwaresynergy.com/blog/$1" />
put it at the top of your other rewrite rules, so it gets executed first, I think it should work.
URL Rewriting does not allow to rewrite path on other domain or subdomain. You can redirect the url by using this code in global.asax:
void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.Path;
if (path.Contains("blog/"))
{
HttpContext.Current.Response.Redirect("http://blog.softwaresynergy.com/blog/");
}
}
Use a custom 404 page.
<system.webServer>
<httpErrors existingResponse="Replace" errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Custom404.aspx" responseMode="Redirect" />
<customErrors mode="On">
<error statusCode="404" redirect="/custom404.aspx" />
Inside the custom404 page I'd put code to do my redirect. Getting the path that caused the error would probably be a combination of...
Request.QueryString("aspxerrorpath");
Request.UrlReferrer;
Once I have the path they were trying to access just do a redirect.
Response.Redirect(NEW_SITE + PATH, true);
I did the change in a different way. Left the original site as php and did the redirect using php rewrite which works fine.
In the domain new.mydomain I did the aspx site
Not ideal, but worked for now.
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.
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