I am developing a website that each user can point his domain to this website. while some of the resources are shared each user can design his own unique website using plugins, ...
I want to create rewrite rules specific for each user. these rules are unique per user but not necessarily in global.
<rewrite>
<rules>
<rule name="Products" enabled="true" stopProcessing="true">
<match url="products/(.+)" />
<action type="Rewrite" url="products.aspx?id={R:1}" />
</rule>
</rules>
</rewrite>
each user will have many rewriting rules each based on content of their own website. I can't just add all rules to one web.config file, right?
what can be done here?
Related
When I installed Wordpress I decided on what I thought would be a decent URL and started writing blog posts and pointing people to www.moreGenericDomain.com/myblog/. Everything worked, and still works, fine. But as my blog focus was narrowed the domain didn't quite suit it anymore.
I've since purchased a new domain that I would like to use. When I go into settings and set www.NewDomain.com as the blog address everything works fine for that domain. Further, the urls are cleaner as they have changed from www.moreGenericDomain.com/myblog/post-1 to www.NewDomain.com/post-1. So everything seemed to go going great.
However, after this change www.moreGenericDomain.com/myblog/post-1 would give a Wordpress 404 page. This is very undesirable as I already have a number of links to my blog posts and a few initial subscribers. I don't want to lose this established traffic that I've worked so hard for.
Is it possible to switch to the new domain name while keeping the old one functional? In other words, I would like www.moreGenericDomain.com/myblog/post-1 to redirect to www.NewDomain.com/post-1.
Update
Per some helpful tips in the comments I tried setting up rewrite rules. My web.config looks like this:
<rewrite>
<rules>
<rule name="multAccounts">
<match url="http://oldDomain.com/LMBlog/post-1/" />
<action type="Rewrite" url="http://newDomain.com/post-1/" />
</rule>
<rule name="darkEssences">
<match url="http://oldDomain.com/LMBlog/post-2/" />
<action type="Rewrite" url="http://newDomain.com/post-2/" />
</rule>
<rule name="GuildBash">
<match url="http://oldDomain.com/LMBlog/post-3/" />
<action type="Rewrite" url="http://newDomain.com/post-3/" />
</rule>
<rule name="KvK">
<match url="http://oldDomain.com/LMBlog/post-4/" />
<action type="Rewrite" url="http://newDomain.com/post-4/" />
</rule>
</rules>
</rewrite>
The first rule seems to work correctly, while IIS ignores the other 3. I've used IIS' rule editor to test my input URL and it says it matches, but when I go to that URL I am not redirected and Wordpress gives me a 404.
I also tried a regex rule:
<rules>
<rule name="RegexRewrite">
<match url="([a-zA-Z\-\:\/]+)oldDomain.com\/lmblog\/([a-zA-Z\-]+)" />
<action type="Rewrite" url="http://NewDomain.com/{R:2}" />
</rule>
</rules>
However, that is completely ignored; no rewrites occur at all and I received the Wordpress 404 page. I suspect that Wordpress is preventing IIS from doing url rewrites.
I have two sites:
http://blog.site.com and http://www.site.com
Both sites are on different servers and different IP addresses (different hosting providers).
I would like to create rule which helps to rewrite the page
The URL will look like
http://www.site.com/logs/current_pages/ to the site visitor but it will really hit
http://blog.site.com/logs/current_pages/
Is it possible?
Please check this, it is not working
<rule name="cname domain">
<match url="/logs/(.+)" />
<action type="Rewrite" url="http://blog.site.com{R:0}" appendQueryString="false" />
</rule>
I'm attempting to write a rewrite rule for the following scenario.
User attempts to load this picture:
domain.com/images/folder/picture.jpg
and instead, I need it to load:
cdn.domain.com/images/folder/picture.jpg.
Here's what I have that isn't working:
<rule name="CDN rewrite for Images">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com" />
<add input="{REQUEST_URI}" pattern="^/images/folder/(.*)$" />
</conditions>
<action type="Rewrite" url="cdn.domain.com/images/folder/{C:1}" />
</rule>
UPDATE: Adding additional info. Most pictures are being served up from Joomla so while the root of the domain is something like domain.com, most images are input with a src="/images/folder/picture.jpg" Not quite sure how this is affecting the rewrite, but none of the options on cheesemacfly's answer below, are working...
UPDATE2: While cheesemacfly was unable to help me in my particular circumstances, I awarded him the bounty and marked his answer as the accepted one because he went above and beyond to try to help me in chat. Hopefully his answer will help someone with rewrites on IIS.
EDIT:
To be able to rewrite (and not only redirect) urls to outside websites, you need to install the Application Request Routing module and enable the proxy mode.
To do so:
Download and install the module
Open your IIS management console (inetmgr)
Select Your server node
Double click on Application Request Routing Cache:
Click on Server Proxy Settings on the Actions pane (right of the screen)
Check the box Enable proxy and click on Apply
The second step is about setting up your rules.
If you want your rewrite to be based on the path then use the following code:
<rewrite>
<rules>
<rule name="Rewrite to cdn domain">
<match url="^images/folder/(.+)$" />
<action type="Rewrite" url="http://cdn.domain.com/images/folder/{R:1}" />
</rule>
</rules>
</rewrite>
Or if you keep the same folder architecture on the second website you can simplify as follow:
<rewrite>
<rules>
<rule name="Rewrite to cdn domain">
<match url="^images/folder/(.+)$" />
<action type="Rewrite" url="http://cdn.domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
If you want to catch only the files ending with a specific extension (let's say images):
<rewrite>
<rules>
<rule name="Forward to cdn domain">
<match url="^images/folder/.+\.(?:jpg|bmp|gif)$" />
<action type="Rewrite" url="http://cdn.domain.com/{R:0}" />
</rule>
</rules>
</rewrite>
Please refer to: http://www.iis.net/learn/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing (section "Which Option Should You Use?")
TIP:
The best way to test your pattern is to use the IIS test pattern tool.
At the root of your website -> URL Rewrite -> Create a blank rule -> click on test pattern:
If you don't get the expected result, you can debug your rewrite using the Failed Request Tracing tool
NOTE: Changing the rule to be a redirect instead of a rewrite fixes the problem. Ideally you want it to be a redirect but I have spent many hours trying to get the rewrite to work, and so far no solutions yet.
<rule name="Rewrite to images.cdn.com" enabled="true" stopProcessing="true">
<match url="images/(.+)$" ignoreCase="true" />
<action type="Redirect" url="http://images.cdn.com/{R:1}" />
</rule>
I want to re-direct from an exact URL request to a new site within that domain.
I need to re-direct requests from
www.example.com/site111/default.aspx?configX.xml
(this site uses a different config file to load content)
to
www.example.com/site222/default.aspx
Issue is that I need to leave access www.example.com.au/site111/default.aspx
so I cannot just to a http re-direct as there is no file called default.aspx?configX.xml
I think I need to use a URL rewrite re-direct
Can someone help me with the syntax for the web config I cannot get it to work
0 module installed and have used the above syntax and it still doesn't work,
If I use the test feature on the module it says that the string matches,
very confused,
the actual webconfig section is here
<rewrite>
<rules>
<rule name="Redirect2" stopProcessing="true">
<match url="\/nrmmaps\/default.aspx\?config=nrmproject.xml$" />
<action type="Redirect" url="/nrmproject/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
and the old link is
http://se.nrmspace.com.au/nrmmaps/default.aspx?config=nrmproject.xml
and I want it to re-direct to
http://se.nrmspace.com.au/nrmproject/default.aspx
Do you have any idea why this is not working?
I believe you need to install the IIS rewrite module which can be found here:
http://www.iis.net/downloads/microsoft/url-rewrite
After you do that, you can add a rewrite section with a redirect rule in your web.config like so:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="\/site111\/default.aspx\?configX.xml$" />
<action type="Redirect" url="/site222/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Hope this helps
I have a .NET site that I am taking down and I plan on redirecting all requests to www.mysite.com using a rewrite rule in the web.config. Should be a simple task, but it's not. I've removed all the content from the filesystem except a single Default.aspx page and a default web.config with the following rewrite rule:
<rule name="Redirect All" stopProcessing="true">
<match url="^(www\.)?mysite\.com(/.+)$" />
<action type="Redirect" url="www.mysite.com" appendQueryString="false" />
</rule>
If I request www.mysite.com/garbage.aspx the server is still trying to look up garbage.aspx, or any other url I provide just as if the rewrite rule was not there.
Very frustrating. Ideas?
Do you want to redirect ALL requests to your new site? If so, this should do it:
<match url=".*" />