IIS redirect and url string replacement - iis

Is there a way to write a redirect rule so that any occurrence, of say "newyork", anywhere in the URL can be redirected to the same url with "new-york" as the string's replacement?

You can achieve this with this IIS Extension:
http://www.iis.net/downloads/microsoft/url-rewrite
It's quite the same as mod_rewrite in Apache.

Related

Redirect # character to homepage using .htaccess

I'm trying to redirect e.g https://example.com/# to https://example.com/. How can I do it using .htaccess?
Thanks!
This is not possible, because the fragment part of the url (#some-element) is not sent to the server. So the server doesn't know about whether you are accessing example.com/# or example.com.

Ignore query string from redirected URL with htaccess

I want to redirect a URL from an old site with this format:
http://www.domain.com/us/productos/producto.asp?id_g=1&ID=2
To this new format:
http://www.domain.com/usa/products/name/
How can I do this? I tried with this:
Redirect 301 /us/productos/producto.asp?id_g=1&ID=2 http://www.domain.com/usa/products/name/
But it didn't work. I think it's because the ? and & symbols of the original URL. For example, this is working in other URLs without this symbols, like this:
Redirect 301 /caste/home/home.asp http://www.domain.com/es
Do you use a php framework?
If you use php framework like codeigniter, setting like that is not in .htaccess, but in application/config.php
Now, You use asp (because your url), you better look first at this link
or you can find google with keyword asp routing or asp pretty url

IIS 8.5 Redirect a subfolder to the same on new subdomain

Trying to 301 redirect traffic from:
www.domain.com/directory/
to
new.domain.com/directory/
It also needs to redirect:
www.domain.com/directory/dynamicallygeneratednames.html
to
new.domain.com/directory/dynamicallygeneratednames.html
I can make the first work easy enough but the second bit I just can't find the correct settings in the url rewrite or the http redirection modules in IIS. The full urls aren't actually files they are dynamically generated.
Any ideas?
You can do this using IIS URL Redirect Module and here is how to use it
then you will have to use some regex to separate parts of the original url
so lets consider www.domain.com/directory/whatever/comes/here/of/any/lengths
you can use this ^(/directory)(/.*)? regex pattern in iis redirect module to separate /directory and /whatever/comes/here/of/any/lengths into two chunks
{R:1} & {R:2} or {C:1} & {C:2} [depends how you use it]
then your final redirect should look like where you chose the new domain, /directory is matched and rest of the url gets transferred over
new.domain.com/{R:1}{R:2} or newdomain.com{C:1}{C:2}

redirect URL IIS on Windows 2008

Hi I need to create for my www.company.com hosted in IIS with .NET apps...a specific RULE that when my URL contain www.company.com/.nsf/etc... redirect my request to a new external URL
external.company.com/.nsf/etc... (then reponde another web-server)
for example:
if the URL is www.mywebsite/page/page.aspx&id=4 responde IIS but when the URL is
www.mywebsite/page/page.nsf&id=4 IIS need to redirect the user to external.mywebsite/page/page.nsf&id=4
Is possible that?
Yes, this is possible.
The redirect rule needs to use 'Regular Expressions'.
The pattern you're looking for is:
^(.*)\.nsf(.*)$
and the Redirect URL would be:
http://external.mywebsite.com/{R:1}.nsf{R:2}
The action type would be 'Redirect' and redirect type can be Permanent (301).

mod_rewrite in .htaccess to replace .aspx

I have converted a website from ASP to php...and the urls no longer require an extension. I want to strip off ".aspx" from the end of my incoming strings (from search engines for example) and then 302 redirect them to the correct page without that extension so that the rest of my mod_rewrite rules can then take over. How would I do this?
OLD URL: www.mysite.com/test/page/here.aspx
NEW URL: www.mysite.com/test/page/here/
Thanks!
Place this rule into your .htaccess file in root folder (before catch-all rewrite rule, if you have such):
RewriteRule ^(.+)\.aspx$ http://www.example.com/$1/ [QSA,NC,R=301,L]
This will redirect http://www.example.com/test/page/here.aspx to http://www.example.com/test/page/here/.
Please note, it is better (at least from SEO/browser point of view) to have 301 redirect code (Permanent Redirect) instead of 302 (Found/Temporal Redirect). Unless you may consider changing website back to aspx.

Resources