Hi I have a site that used to have a separate mobile side which had links indexed by google. I’ve now changed that to a responsive design. I’m on a shared server so I have to do this redirect through URL Rewrite, is there any way that I can redirect anything and everything that comes after the /mobile/ subfolder that used to exist to its equivalent in a root folder with one rule. So that the following would happen:
Domain.com/mobile -> domain.com
Domain.com/mobile/folder1/page1/variable -> domain.com/folder1/page1/variable
Domain.com/mobile/folder1/page2/variable -> domain.com/folder1/page2/variable
Domain.com/mobile/folder2/page1/variable -> domain.com/folder2/page1/variable
Domain.com/mobile/folder2/page2/variable -> domain.com/folder2/page2/variable
That would look something like the following in your web.config (basicall match all "root" requests that start with mobile/ and redirect to the equivalent (using a 301 which is the right one for SEO purposes):
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect mobile" stopProcessing="true">
<match url="^mobile/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Related
I'm trying to write a rewrite rule in on Windows Server 6.2. Although I used IIS Manager to create the code, it didn't work.
I tried stopProcess true/false, used different regex, restart server several times. Nothing changed. I followed the whole steps on Microsoft's web site on https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="[^\/]+\/\/([^\/]+:?[0-9]?)\/.*" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I want to show only main URL. My domain is http://e-campus.example.com.
For example if someone go to that link: http://e-campus.example.com/Login/Student
Server should rewrite to this:
e-campus.example.com (with hiding http:// but it's not important)
So basically I just want to show main URL. But it keeps showing full path. What am I missing here?
According to your description, I found your regex match the whole url. But the iis url rewrite will not get the whole domain, it will just get the part of the url not the whole url.
For example:
If your url is http://e-campus.example.com/Login/Student., the match url part is
login/Student.
So if you want to rewrithe all the request to e-campus.example.com, you should use below url rewrite rule.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://e-campus.example.com/" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm trying to use content hosted on a subdomain site as a sobfolder on same domain. (On different servers)
mydomain.com -> is main domain.
sub.mydomain.com -> is sub domain.
mydomain.com/sub -> is what I want to show my sub domain content on.
on my main domain, I changed Application Request Routing as "enable proxy" and used code below, on the web.config
<rewrite>
<rules>
<rule name="Reverse Proxy to fuarlar" stopProcessing="true">
<match url="^sub/(.*)" />
<action type="Rewrite" url="http://sub.mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
But It didn't work. (on www.mydomain.com/sub gives me an error that '404 not found')
What should I make for that?
Whats wrong with my configuration?
What should my steps be?
www.mydomain.com/sub does not match ^sub/(.*). You are missing a slash at the end of your URL.
Is it possible to remove a directory from a URL without using a redirect action? In other words can I do it with only a "rewrite" action.
I need to take a URL like this: http://www.example.com/de/folderabc/specs/default.aspx and remove the "folderabc" directory to make it like this: http://www.example.com/de/specs/default.aspx
So far any variation I have tried like this is not working:
<system.webServer>
<rewrite>
<rules>
<rule name="removefolder" stopProcessing="true">
<match url="folderabc/(.*)" />
<action type="Rewrite" url="/{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
I am using IIS 7.5.
Try putting a caret ^ in your url to match on.
<match url="^folderabc/(.*)" />
I have the following url rewrite code in my web.config
I want to forward anything .htm to the brand.aspx.
so if anyone type in
test1.htm
test2.htm
test3.htm
would go to the brand.aspx. However, the following url rewrite would work if there is an actual file call "test1.htm" in the server, then it will redirect to the brand.aspx. If there is no file exists, it will just return 404 instead of redirect to the brand.aspx. Does anybody know why? thanks a lot.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="test" stopProcessing="false">
<match url="(.*)\.htm$" ignoreCase="true" />
<action type="Rewrite" url="brand.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
There is a similar thread
Using a custom URL rewriter, IIS6, and urls with .htm, .html, etc
I have experienced a similar issue before and i made a custom IHTTPModule
for which i used the guide at
http://msdn.microsoft.com/en-us/library/ms227673.aspx
I have written an app to replace a single page and need to redirect the requests for the old page to the new app.
In IIS, how would I redirect the request for
http://www.mysite.com/foo.aspx
to
http://www.mysite.com/bar/default.aspx
Thanks!
In your web.config do:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Foo_To_Bar" stopProcessing="true">
<match url="^foo.aspx" />
<action type="Redirect" url="/bar/default.aspx" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
If you don't want to write the redirects by hand, there is a tool for URL Rewrite and Redirects: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module The installer says it is for 7.0 but it works with 8.5 as well.
What you need is URL rewriting. There are a number of options. Some are discussed in this question:
IIS URL Rewriting vs URL Routing