IIS Rewrite to replace string in URL - iis

I am trying to implement an IIS redirect that is basically a string replace.
Here I what to change old to new. The other parts of the URL should not change and they can be in different formats.
localhost://part1/old/part2/something-old
to
localhost://part1/new/part2/something-new
and
localhost://part1/old/part2/part3/nothing-old
to
localhost://part1/new/part2/part3/nothing-new

Related

String replacement with htaccess?

Some of my sites sometimes get encoded url queries which will redirect to a error page but i would like to support some of these.
With htaccess how could you replace a url like this:
http://website.com/%3Fpage%3Dbdyb2y21ybar3h35
With this:
http://website.com/?page=bdyb2y21ybar3h35
Edit: I would like to do this directly within the .htaccess rather than decode with PHP etc.

RewriteRule - redirect multi variable URL to multi variable URL

Our old website has a search URL structure like this:
example.com/Country/United States/Region/California/Area/Southern California/City/San Diego/Suburb/South Park/Type/House/Bedrooms/4/Bathrooms/3/
This is currently rewritten to point to the physical page:
/search/index.aspx
The parameters in the URL can be mixed up in different orders, and the URL can include one or more parameters.
We want to 301 redirect these old URLs to a new structure that is ordered in a logical way and more concise:
example.com/united-states/california/southern-california/san-diego/south-park/?type=house&bedrooms=4&bathrooms=3
example.com/united-states/california/?type=house&bedrooms=4&bathrooms=3
Is there a way with URL rewriting to interrogate the old URL, work out what parameters are existing and then write out the new URL structure?
Even if we can limit it to just the Country, Region, Area, City and Suburb, that may be good enough to at least return some results even if it's not perfect.
Also, spaces should be turned into hyphens and all text made lowercase.
I already have the RewriteRule to turn the new URL structure into a URL to point to a physical page. It's just transforming the old URL in to the new URL I need help with. I've googled endlessly and it's just beyond me!
Can anyone help? Thanks.
Since you already have the old search page with rewriting rules set up for it and which is capable of parsing all parameters you need, the easiest and most appropriate solution I see here is to issue a redirect you require from this old search page's code. Just put the code that composes new URL with all parameters needed and redirects from this page - this should be a lot easier than trying to parse all these parameters in .htaccess and combine them into the new format.

Redirect to URL with umlauts or accents via .htaccess

To redirect to a new URL that contains diacritics via .htaccess, what is the correct and safe way?
Can I somehow set the .htaccess file to UTF-8 and just use the non-ASCII characters, e.g.:
redirect 301 / http://www.bücher.ch/
Need I use the ACE string instead, e.g.:
redirect 301 / http://www.xn--bcher-kva.ch/
Is urlencode the way to go? I tried the following without success:
redirect 301 / http://www.b%C3%BCcher.ch/
For context, the following page on internationalized domain names (IDN) has a section about the technical solution to include accents and umlauts in domains.
In the domain part, you must use ASCII Compatible Encoding (ACE).
In the rest of the URL, you use urlencode. So, in .htaccess…
http://www.bücher.ch/schöne/
…needs to be written as…
http://www.xn--bcher-kva.ch/sch%C3%B6ne/

.htaccess internal rewrite with preserving query string

i need to rewrite a url, preserve one query string for internal rewrite.
and another for display.
so this current url:
www.mysite.com/staff/teachers?id=37:john
needs to be internally rewritten to:
www.mysite.com/staff/teachers/37
not quite sure where to start, im trying this, but don't know how to access the number between "id=" and ":" to use for the rewrite
thanks for your help.
You cannot rewrite a URL "for display". All you can do is tell the browser to load a new URL. When the browser requests the new URL, the server has no way of knowing why it is being loaded (i.e. that it was the result of a previous redirect) so that new URL will need to include enough information to load the actual page.
In other words, you have to either:
include the ID in the "pretty" URL, such as www.mysite.com/staff/teachers/37-john
have your application look up the user based on their name in the internally rewritten URL, e.g. www.mysite.com/staff/teachers?lookup_name=john

Need URL Rewrite to replace a string in a url

I am looking and looking and coming up with all different patterns, but no such luck. I require a rewrite rule to handle the a replacement of a string xyzlisting with xyz-listing. It may be anywhere in the url. Is there a straightforward way to write this rule?
I am not so experienced with IIS. However, I can suggest something:
In Apache mod_rewrite, you can use this rule:
RewriteRule (.*)(/\w+)(listing)(.*)$ $1$2-$3$4
This rule will split whatever string in the format anything followed by 'listing' that comes after mydomain.com/ with a '-'. Which results in 'anything-listing', wherever in the URL.
This will only change the last occurrence of this type of string. It will not replace more than one occurrence.
You can import this URl rewrite rule from Apache to IIS using this IIS extension:
IIS Extenson page for url rewrite module
Hope this helps :)

Resources