I did a bit of search but can't find a complete answer to my question:
I wonder if it's possible to set my IIS 7.5 to map one "custom" extension to another "physical" extension.
Eg.
I have Default.aspx, I'd like my server to serve this file to a request of Default.foo.
The mapping questions/answers I found are all about having Default.foo files, and mapping them to the proper handler; that's not my case, I just like to have a sort of masking of the real physical file extension.
Is it possible?
TY
The mapping should be setup between default.foo and default.aspx, mapping extensions cannot achieve this goal. You may use URL Rewrite module to create a rule to rewrite default.foo to default.aspx.
A simple example is as below,
<rewrite>
<rules>
<rule name="foo" stopProcessing="true">
<match url="(.*)\.foo" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>
Related
I am trying to rewrite the URL on an Azure MVC application. The solution contains many projects, thus has web.config files all over the place.
The URL Rewrite objective is to send all URLs based on the Project "Statistics" to the subdomain "admin", whatever subdomain was called at the origin of the request. (I created this rule independently on my laptop with IIS Manager and imported it manually in one of the projects)
<configuration>
<system.webServer>
<!--Something here. The rule nests at the end of the block. -->
<rewrite>
<rules>
<rule name="Statistics">
<match url="[0-9a-zA-Z-]*.mysite.com/statistics/(.*)" />
<action type="Rewrite" url="https://admin.mysite.com/statistics/{R:1}" />
</rule>
</rules>
</rewrite>
</configuration>
</system.webServer>
So, I am wondering why this rule doesn't seem to be executed:
Is the syntax correct?
In which web.config file should I place this rule, considering that I have five projects in the Solution?
We'd like to slightly alter our web.config file in different slots. For example, we'd like to redirect and proxy to different urls in different slots. I was thinking about using app settings, which can be read as env variables, but I couldn't find a way to use them in the XML. I image something like this:
<rule name="Reverse proxy" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="{ENV_EXTERNAL_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
That {ENV_EXTERNAL_HOST} part is of course wrong. Is it possible to use these settings from the contents of the web.config XML file?
We ended up using rewrite maps to map incoming urls to different values.
So I have a project in azure that is www.example.com and it has it's MVC file structure with source code and all. However, within that, I have another part that needs it own URL, www.example2.com which would point to a folder within this hierarchy. So you could reach this entry point from www.example.com/#/example2.html or simply from going to www.example.com. Hope that makes sense. So within Azure, how can I achieve this? I am looking through custom domain, but not seeing a way to go about this. Any ideas please?
Yes, using rewrite rules in your web.config. Adjust variables accordingly.
<rewrite>
<rules>
<rule name="Redirect domain" enabled="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?example2\.com$" />
</conditions>
<action type="Rewrite" url="folder/{R:1}" />
</rule>
</rules>
</rewrite>
Don't forget to add and authorize both domains to your web app.
I'm developing my first website and just learnt about the web.config file for IIS, so what I'm trying to do is to hide different parts of the url.
For example the homepage is www.domain.com/it/homepage.html and I'd love to make it appear as www.domain.com/it/homepage
I haven't found anything about removing an .html extension on the net, just a lot of .aspx which I tryed to replace with .html, failing miserably.
Another side question: is it possible to redirect errors with web.config ? I've seen a lot of .htaccess based solutions but that's it.
EDIT: Forgot to say that the website is hosted by ARUBA, on their windows oriented server
You are trying to change the URL of your site, which is the way to access it... that's a pretty odd action to do. When you get a request to your server for a certain page, the URL is parsed as the path to that file. If you want to change the URL, you need to change the name of the file - and if you wouldn't like having a .html in the end, then perhaps the file shouldn't be a html file - however, your goal is different. You want to have no extension at all.
Luckily, there is a way to have a url endpoint which doesn't have any file extension is all. That would be a folder. Folders dont have an extension to them, however they have no content by themselvs except the file they're linking.
Side note: There's another way, which is the one you'd usually see around the web. PHP could have other things in the URL than just the endpoint, but you asked about windows based HTML/ASPX windows backed pages.
So - yeah, the only way I see to have no extension at all is letting the user navigate through folders. The only question left is, why would you want this anyway?
You can use the following configuration in your web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="niceURL" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I have been trying to rewrite the URL in classic ASP. I am currently using IIS 7.5. I tried to use the URL Rewrite plugin which converts the following link:
http://blog.johnavis.com/blog/default.asp?id=19
into something like this:
blog.johnavis.com/19/
blog.johnavis.com/id/19/
blog.johnavis.com/blog/default/19
blog.johnavis.com/blog/default/id/19
I want to convert into something like this:
http://blog.johnavis.com/blog/myblog/
Can that be achieved? Any help would be appreciated.
Basically all the rewrite module does is to edit your web.config file. You're probably better off editing the file yourself. You'll find that it has created a section called rewrite, add the following rule
<rewrite>
<rules>
<rule name="My Blog">
<match url="blog/myblog/" />
<action type="Rewrite" url="blog/default.asp?id=19" />
</rule>
</rules>
</rewrite>
You can achieve this by creating URL rewrite rule in IIS Manager by defining a pattern. Use the following links to learn about that.
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-video-walkthrough
Hope this helps...