Adding code to web.config to hide my page extensions - asp.net

I have this web.config file and i want to add a code to it that will hide the .asp of a page in my website called "users.asp" . please how do i do it
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>

Obviously you need the URL rewrite module installed, and you need IIS7 or above, this won't work on IIS6
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^users/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="users.asp" />
</rule>
</rules>
</rewrite>
Recommended reading:
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

Related

IIS URL Rewrite to querystring parameter

I need to capture requests to folders that aren't file folders to be redirected to a default page with the requested path as the querystring.
For example, if the user requests
www.mysite.com/IT
I want it to redirect to
www.mysite.com/default.aspx?q=IT
However, if they request a page that is in a real sub-folder, that shouldn't be redirected. For example, requests to www.mysite.com/projects/new.aspx shouldn't try to do any re-directions as it's a physical folder and file in the site.
Use the IIS Rewrite module and the set it up in the web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirector" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{PATH_INFO}" pattern="/*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/default.aspx?q={PATH_INFO}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You could define a 404 error page that would redirect to your default page with the "q=" that you desire

Wordpress Permalink for Application

Please read this first:
When i activate my custom permalinks on main blog, everything works well.
But i activate permalinks on sub blog, nothing works even wp-admin panel. I got 500 error.
I have blog on main website on IIS and opened new application under this. I load my wordpress on this applcation without any problem. But when i activated permalinks for this application too, i got 404 error.
My main website config;
Permalink pattern = /%category%/%post-name%/
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url=".*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<modules>
<remove name="RewriteModule" />
<add name="RewriteModule" />
</modules>
</system.webServer>
<location path="analytics"></location>
</configuration>
As you can see i have main-web-site/analytics for my sub blog. All permalinks works fine on main website but not working on sub blog. When i activate permalinks, sub website creating web.config file and after that i got 500 error. After i delete this web.config file, i can browse on sub blog but when i click to links i got 404 error.
and this is my sub-blog web config;
Permalink pattern : /archives/%category%/%post-name%
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Any helps would be nice.
Thanks already! :)

Web.Config issue with Wordpress

I have a site that uses Worpress on part of it. I am having trouble with the index page.
With index.php the site loads the most recent posts, which is the desired action with the incorrect url. Without index.php, which is the desired url, the page loads the 404 template.
I have the site working locally correctly. The only thing I can think of, is the web.config is incorrectly routing this request. Since this is an area I don't deal well with, I was hoping to get some help to see if that was the issue.
Here is the web.config contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 2-1" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
It sounds like you don't have index.php in the list of Default Documents. Add index.php to the list as shown below. You can also do this through the IIS settings for Default Document.
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="index.asp" />
<add value="Default.asp" />
<add value="Default.htm" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>

Configure IIS URL Rewrite module for AngularJS HTML5Mode Still Not Working

I have searched at found some info on configuring IIS URL Rewrite module to work with AngularJS HTML5Mode and even tried the info I found on another question:
How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?
I've made the changes to my IIS as displayed in the question found in the link above and set the base URL and the site works when I visit the root site (i.e. http: //localhost/appname/). All of my views and the routing works fine.
However; when I try to visit a specific URL (i.e. http: //localhost/appname/about) in a new tab or browser window, I get a 404. Is there something else I'm missing???
I'm running Windows 7, IIS 7 with the URL Rewrite Module installed.
** I had to space the protocol out to allow the example URL to be accepted.
Install this extension: https://www.iis.net/downloads/microsoft/url-rewrite
And add this to web.config under system.webServer
<rewrite>
<rules>
<clear />
<rule name="Html5Mode" enabled="true" stopProcessing="true">
<match url="^(.+)$" negate="true" />
<conditions>
<add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" logRewrittenUrl="true"/>
</rule>
<rule name="AngularJS" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
Here is the full web.config including serving static files.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Html5Mode" enabled="true" stopProcessing="true">
<match url="^(.+)$" negate="true" />
<conditions>
<add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" logRewrittenUrl="true"/>
</rule>
<rule name="AngularJS" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
<handlers>
<clear />
<add
name="StaticFile"
path="*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
<staticContent>
<mimeMap fileExtension=".*" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>

URL rewrite - web.config error

I am getting the following error when i run my .aspx page.
Error Code0x8007000d
The configuration section 'rewrite' cannot be read because it is missing a section declaration
I have a simple v.aspx page which has the following code:
Response.Write(Request("q"))
My hosting server as IIS 7 installed with URL rewrite feature enabled (that's what they claim)
My web.config file has the following lines under :
Note: The node has blue squiggly lines under it
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
I have searched stackoverflow but did not find a solution.
May be someone found a solution.
TIA
Make sure your <rewrite> is enclosed in the <system.webServer></system.webServer> section.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Install the URL Rewrite module http://www.iis.net/download/URLRewrite and that should be sorted. It fixed my problem
The rewrite section in system.webServer is supported in IIS7, but not IIS6. The error is likely caused by deploying this site to a server that's only running IIS6.

Resources