at first. I have searched and read here a lot and googling with bing but didnt find
the solution. In my local enviroment it just works. Iam no IIS Admin so ....
i try the following
My domain "http://mysite.com/" goes to my url provided by my hosting service
(discountasp.net)
I want that this url goes to the root/mysite/ virtual directory but i want that the
url stays on "http://mysite.com/". So i defined the following rule, but it doesnt
work for me.
here is my web.config that is placed in the root directory (generated by the IIS7
Remote Administration UI)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="mysite">
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="mysite.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?mysite.com" />
</conditions>
<action type="Rewrite" url="\mysite\{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The "#Html.ActionLink" creates a link with the virtual directory
"http://mysite.com/mysite/"
I got it. Pointing my Domain directly on the subfolder and defining a Outbound rewrite rule on iis solves my problem.
Related
I'm working on a client application where they have a nested HTML-only app in a rooted subfolder of an otherwise ASP.NET application.
The domain name is changing for the HTML app only, and I need to be sure that the requests are routed to the new domain name. So, using the rewriteRules sounds like a perfect tool for this, but I'm doing something wrong and need another set of eyes.
The original URL is something like this:
https://example.com/folder1/folder2/app/index.html
The new domain is on an entirely different server and I want all requests from the app folder to go to the new domain name. Here is an example:
https://newdomain.com/folder1/folder2/app/index.html
Unfortunately, I'm doing something wrong that's probably obvious... I keep getting this URL in the redirect.
https://newdomain.com/index.html
Here is the web.config showing what I tried. It's in the app folder.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="RedirectHtmlApp" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)?example\.com$" />
</conditions>
<action type="Redirect" url="https://newdomain.com/{R:0}" redirectType="Permanent" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
{R:0} and {R:1} both return index.html.
What is passed to {R:0} is relative. So if your web.config is in /folder1/folder2/app/{here} then "folder1/folder2/app/" are not passed along. If your web.config rule is in the root of the site-app above /folder1, then I am wrong, but if I am right, then you just need to include the path to the root of the app at the destination also. Given what you have above,
<action type="Redirect"
url="https://newdomain.com/folder1/folder2/app/{R:0}"
redirectType="Permanent" appendQueryString="true" />
I have a really harsh time trying to get Symfony 3 app work on IIS as website subdirectory.
Structure on IIS :
Application is called pfc and its poiting to directory pfc/web, (IIS is hiding root, because folder name is same as app)
This is web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="app_dev.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<clear />
<rule name="StaticFiles" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="{R:0}" logRewrittenUrl="true" />
</rule>
<rule name="Symfony 3" enabled="true" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="./app_dev.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Entering dev.erp.loc/Test2/pfc ends up with:
like Symfony thinks of itself as a root application, which is not.
My best shoot was to use router.request_context.base_url, but it looks like it worked only in S2.
Now im stuck on something i can call half-way solution
By comment rewrite section in web.config i was correctly redirected to Identity Server, but after log in i get :
In order to fix it, i needed to uncomment rewrite section, to make routing work again, but it works only for browser, leaving it in this state will cause "no route found" in anther browser.
It would be nice to fix subdirectory routing in parameters.yml, which I fill anyway in deploy script, but if there is no other way I can edit web.config too.
Recently I needed to take care of similar issue and as side effect I solved this "problem". My URL without trailing slash is correct. The issue was that Chrome couldn't create canonical url form and made request to endpoint that Symfony don't need to interpret
I have a webpage hosted on a shared Microsoft-IIS/8.5 server.
I don't have the admin privileges on that server, and I don't have access to its configuration files, so I can't really make sure that the URL rewrite module or the HTTP redirect element are correctly installed / set up.
I would like to establish a redirection from a folder named old_folder to a folder named new_folder (both at the root for me, i.e., at http://sharedhosting.com/myusername/).
I placed in the root folder the following web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
<system.webServer>
<rewrite>
<rules>
<rule name="attempt" stopProcessing="true" enabled="true">
<match url="^old_folder/$" />
<action type="Redirect" url="new_folder/" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But all I can get is a 403 - Forbidden: Access is denied. (if I leave an empty old_folder) or a 404 - File or directory not found. (if I erase it).
I tried using the HTTP Redirect, by placing in old_folder a Web.config file containing
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://sharedhosting.com/myusername/new_folder/" />
</system.webServer>
</configuration>
But that didn't worked either.
I know that my Web.config files are read (I can get 500 errors if there is an error in them). I suspect that the URL rewrite is installed, since, for instance, http://sharedhosting.com/myusername/folder is rewritten to http://sharedhosting.com/myusername/folder/ (i.e., with a slash) if the folder folder exists.
Is my rule correct? Does my host prevent me from redirecting? If yes, how can I tell?
I added a <clear /> after the <rules> tag to discard all the other rewriting rules, but it still isn't redirecting anything.
What am I missing?
LAST EDIT BEFORE THE BOUNTY EXPIRES
To clarify, my question is "How to understand why the server isn't correctly interpreting / ignoring my instructions?".
We came to the conclusion that it was probably my server that was weirdly set-up, I'm precisely trying to "revert-engineer" that and to detect what's making the server ignore the redirect / rewrite rules.
You can achieve the same thing by using the HttpHandlers , so i'm presuming that you can access the both Old_folder and New_folder directly in the browser .
Here is a sample httphandlers , you can do in this way :
youname.Handlers
{
public class RedirectHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Status = "301 Moved Permanently";
string url = context.Request.Url.ToString().Replace("old_folder", "new_folder");
context.Response.AddHeader("Location", url);
}
public bool IsReusable
{
get { return false; }
}
}
}
In web_config add the handler as follows:
system.web>
<httpHandlers>
<add verb="*" path="xxx/*.*" type="yourname.Handlers.RedirectHandler"/>
</httpHandlers>
</system.web>
Using IIS Url_rewriting :
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="yourRedirects">
<add key="/yourroot/old_folder/" value="/otherdir/new_folder" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="RedirectRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{yourRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://www.yourdomain.com{C:1}" appendQueryString="False" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I think this can be done with a simple rewrite rule.
<rule name="ToNewFolder" stopProcessing="true">
<match url="^old_folder/(.*)" ignoreCase="true" />
<action type="Rewrite" url="new_folder/{R:1}" />
</rule>
The above rule will send all requests to the new folder, but keeps the old url with old_folder in it. If you want the url to change it's display to new_folder in it, use
<rule name="ToNewFolder" stopProcessing="true">
<match url="^old_folder/(.*)" ignoreCase="true" />
<action type="Redirect" url="new_folder/{R:1}" />
</rule>
Tested it on my local machine with folders, subfolders an requests with a QueryString. I hope this works on shared hosting also.
We have an azure hosted site at www.roburir.com (built in asp)
I am wanting to add a wordpress site at the url www.roburir.com/articles.
Have created and successfully deployed a wordpress site at:
http://robur-articles.azurewebsites.net
Have then written a rewrite code in the web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SEOAzureRewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^robur-articles.azurewebsites.net$" />
</conditions>
<action type="Redirect" url="http://www.roburir.com/articles{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This redirect works, however I am getting a 404 error and the message:
You do not have permission to view this directory or page.
Have tried moving the webconfig to different folders but still no joy.
Any help would be much appreciated cheers!
You will need to create a virtual directory "articles" on your www.roburir.com site then deploy your WordPress site to it.
You can follow this article for a full description of the method:
https://blogs.msdn.microsoft.com/kaushal/2014/04/19/microsoft-azure-web-sites-deploying-wordpress-to-a-virtual-directory-within-the-azure-web-site/
We are using IIS7 URL rewrite module with asp.net C#, all of the URLs are configured and written directly into web.config:
<system.webServer>
<!-- ... -->
<rewrite>
<rules>
<clear />
<rule name="Category URL" stopProcessing="true">
<match url="somepage.aspx" ignoreCase="false"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="REDIRECTION=true"
ignoreCase="false"/>
<add input="{QUERY_STRING}" pattern="categoryid=([^&]*)"/>
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/browsing/categorylanding.aspx?navcategoryid={C:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
I need to move this to a section so that I can have seperate rules for QA, DEV and Production, what would be the "type that i would define in the section?
<configSections>
<section name="IISURLRewriteSection" type="???"/>
</configSections>
Will the IIS automatically pick up these settings once moved outside from web.config to another custom config file?
We resorted to writing our own HTTPModule since from debugging point of view as well any issues that would arise at IIS level would have to have the Operations team involved - just following a process defined in our org :)
The best solution, imho, would be to move the configuration details into external files, which you can then swap out per-environment.
This is pretty easy to do using the method described in Moving IIS7 url rewrite section out of the web.config file, where you would have something like this in your Web.config file:
<system.webServer>
<rewrite configSource="rewrite.config"/>
</system.webServer>
Then you can store the environment specific stuff in a separate file, rewrite.config, looking something like this:
<rewrite>
<rules>
<clear />
<rule name="Category URL" stopProcessing="true">
<!-- ... --->
</rule>
</rules>
</rewrite>