Asked by:
URL Rewriting Not working in Asp.net framework 4.0 (Very Urgent.......)

Question
-
User-1199691179 posted
1. The current home page url must be
changed from https://www.jetfleet.co.in/Home/Homepage.aspx to
https://www.jetfleet.co.in/
2. In all other urls like
About : https://www.jetfleet.co.in/Common/About_Us.aspx
Service : https://www.jetfleet.co.in/Common/Our_Services.aspx
Career : https://www.jetfleet.co.in/Common/Careers.aspx
Contact Us : https://www.jetfleet.co.in/Common/Contact_Us.aspx
Removal of "common" from the above
URLSo, Please Advoice how can we achive the same .
we have already tried from IIS7 and Web.config ,but it's not working
please check belows code and advoice.
<rule name="Rewrite to folder1" stopProcessing="true">
<match url="Common/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^http://10.1.0.15/JetPortal/$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="http://10.1.0.15/JetPortal$/{R:1}" />
</rule>
<rule name="Rewrite to folder2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^http://10.1.0.15/JetPortal/Homepage.aspx$" />
</conditions>
<action type="Rewrite" url="abc/{R:1}" />
</rule>Thursday, September 19, 2013 8:24 AM
All replies
-
User1508394307 posted
It seems that you misunderstood the role of match url condition. This is for entered url, not for target.
So, you should not use
<match url="Common/(.*)" />
if this is to be target.
Instead you can try
<match url="(.*)" />
<action type="Rewrite" url="Common/{R:1}" />To avoid redirect of / to /Common/ you can try to add a negate rule
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="true" pattern="^/default\.aspx$" ignoreCase="true" />
</conditions>Hope this helps.
Thursday, September 19, 2013 8:54 AM -
User-1199691179 posted
I have tried this but showing error
The Web server is configured to not list the contents of this directory
<rules>
<rule name="Rewrite to folder1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="true" pattern="^/Homepage\.aspx$" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="Common/{R:1}" />
</rule>Please advoice.........
Friday, September 20, 2013 12:52 AM -
User1508394307 posted
The error says that it cannot show contents of the directory, which means that your target request is a directory such as /common, but must be /common/page.aspx
If you request https://www.jetfleet.co.in/About_Us.aspx
it should be rewritten to https://www.jetfleet.co.in/Common/About_Us.aspx
Friday, September 20, 2013 2:29 AM -
User-1199691179 posted
I have tried the below code in config but it showing error
The Web server is configured to not list the contents of this directory
<rule name="Default Document URL Rewrite" stopProcessing="true">
<match url="(.*?)/?/Homepage\.aspx$" />
<action type="Redirect" url="{R:1}/" logRewrittenUrl="true" />
</rule>please advoice ................
Friday, September 20, 2013 6:34 AM -
User1508394307 posted
Because you specified directory (notice slash at the end) as a target of redirect
type="Redirect" url="{R:1}/"
Also, why "Redirect" and not "Rewrite"?
Friday, September 20, 2013 7:11 AM -
User-1199691179 posted
"/" is already there but also check with Rewrite then it showing error
The requested page cannot be accessed because the related configuration data for the page is invalid
Friday, September 20, 2013 7:19 AM -
User-1426144113 posted
Hi,
I suggest that you can refer to http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference that you can understand clearly about that.
On the other hand, for this issue I suggest that you can post it in http://forums.iis.net/
Thanks
Saturday, September 21, 2013 11:49 PM -
User-1199691179 posted
Still not working the code
showing error.
Please give another way to achive...................
Monday, September 23, 2013 6:45 AM -
User-1199691179 posted
Please see the belows eg. here i want url
http://localhost:57011/TestURL/Default.aspx
instate of
http://localhost:57011/TestURL/Home/Default.aspx this
please help........
<?xml version="1.0" encoding="UTF-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <membership> <providers> <clear /> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear /> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> </providers> </profile> <roleManager enabled="false"> <providers> <clear /> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <rewrite> <rules> <rule name="Deafult URL" stopProcessing="true"> <match url="(.*?)/?Default\.aspx$" /> <action type="Redirect" url="{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Monday, September 23, 2013 7:21 AM -
User-1426144113 posted
Hi,
<system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <rewrite> <rules> <rule name="Deafult URL" stopProcessing="true"> <match url="(.*?)/?Default\.aspx$" /> <action type="Redirect" url="{R:1}" /> </rule> </rules> </rewrite> </system.webServer>
How do you get that code? Do you configure it in the IIS. Please refer to http://weblogs.asp.net/owscott/archive/2010/01/26/iis-url-rewrite-hosting-multiple-domains-under-one-site.aspx
Thanks
Monday, September 23, 2013 9:59 AM -
User-1454326058 posted
Hi rahul,
Thanks for your post!
According to your description, I did a sample that can help you:
http://www.urlroute.com:5566/About_Us will rewrite to http://www.urlroute.com:5566/Common/About_Us.aspx
<system.webServer> <rewrite> <rewriteMaps> <rewriteMap name="TestRe"> <add key="/About_Us" value="/Common/About_Us.aspx" /> </rewriteMap> </rewriteMaps> <rules> <rule name="TestRewrite"> <match url=".*" /> <conditions> <add input="{TestRe:{REQUEST_URI}}" pattern="(.+)" /> </conditions> <action type="Rewrite" url="{C:1}" appendQueryString="false" /> </rule> </rules> </rewrite> </system.webServer>
Thanks
Best Regards
Monday, September 23, 2013 11:42 AM -
User1508394307 posted
"/" is already thereWhat I mean is that there must be no slash at all.
Monday, September 23, 2013 12:38 PM -
User-1199691179 posted
Dear Friends....
Let me clear u all again..1)I have just added new website.
2)In that i have created one folder name Home.
3)Inside that folder i have added Homepage.aspx page.
5)When i run the Homepage.aspx from IIS it shows the urlhttp://10.1.0.15/Jetcar/Home/Homepage.aspx
6)But i want to rewrite this url as
http://10.1.0.15/Jetcar/Homepage.aspx
i want to remove the folder name..
7) Also i have 1 index.html page.
index.html code:
<script language="javascript" type="text/javascript">
window.location = "http://10.1.0.15/Jetcar/Home/Homepage.aspx";</script>
in index.html i have set the path which comes first as an output when i run the project.
8) for this i have done the changes in web.config file also..
web.config Code<rule name="MyRole" stopProcessing="true">
<match url="Home/(.*)" />
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
Still it shows the error[B]The resource cannot be found. [/B]
and URL is Same http://10.1.0.15/Jetcar/Home/Homepage.aspx
please give me the solution for this ...................Tuesday, September 24, 2013 3:13 AM -
User1508394307 posted
<match url="Home/(.*)" />I already told you that this is incorrect.
In the match tag must be url which you want to have. Not the one which you already have.
6)But i want to rewrite this url as
http://10.1.0.15/Jetcar/Homepage.aspx
So, in this case you need to have
<match url="Jetcar/Homepage\.aspx />
Please read the above answers as well as documentation for url rewrite module.
Tuesday, September 24, 2013 3:20 AM -
User-1199691179 posted
<rule name="MyRole" stopProcessing="true">
<match url="Jetcar/Homepage\.aspx"/>
<action type="Rewrite" url="/{R:1}" appendQueryString="true" />
</rule>
i have put this code but same url i got
Tuesday, September 24, 2013 4:47 AM -
User1508394307 posted
What I understood from the above, you wanted to have
<action type="Rewrite" url="/Jetcar/Home/Homepage.aspx" appendQueryString="true" />
Also, get rid of javascript in index.html as it might confuse.
Tuesday, September 24, 2013 5:19 AM -
User-1199691179 posted
so is this right? but not working
<rule name="MyRole" stopProcessing="true">
<match url="Jetcar/Homepage\.aspx"/>
<action type="Rewrite" url="/Jetcar/Homepage.aspx" appendQueryString="true" />
</rule>and
So what should i do with index.html.................
Tuesday, September 24, 2013 5:27 AM -
User1508394307 posted
but not workingPlease always describe the issue in details. Saying "not working" will not help to understand it.
You told that
7) Also i have 1 index.html page.
index.html code:
<script language="javascript" type="text/javascript">
window.location = "http://10.1.0.15/Jetcar/Home/Homepage.aspx";</script>
Can you explain what is this and why do you need it?
Tuesday, September 24, 2013 6:00 AM -
User-1199691179 posted
In that i have put the path of url and
in IIS Default document i set index.htm in first position
so it call first when project run from iis
Tuesday, September 24, 2013 6:12 AM -
-
User-1199691179 posted
But i did not want to show folde name in URL
Tuesday, September 24, 2013 7:17 AM -
User1508394307 posted
5)When i run the Homepage.aspx from IIS it shows the url
http://10.1.0.15/Jetcar/Home/Homepage.aspx
If you mean you want to type
http://10.1.0.15/
and it should be rewritten (not redirected) to
http://10.1.0.15/Jetcar/Home/Homepage.aspx
then you should not use javascript to redirect pages (see my post above)
Instead, create a new rule
<rule name="Root" stopProcessing="true"> <match url="^$" /> <action type="Redirect" url="/Jetcar/Home/Homepage.aspx" /> </rule>
Index.html must be deleted as not required.
Tuesday, September 24, 2013 11:43 AM -
User-1454326058 posted
Hi rahul,
rahul_shinde
But i did not want to show folde name in URLIf you don't want the URL contain the folder name, I suggest that you can use the URL Rewrite.
On the other hand, I would like to know that if the Jetcar is a Virtual Directory.
If so, this code below is incorrect.
<rule name="MyRole" stopProcessing="true"> <match url="Jetcar/Homepage\.aspx"/> <action type="Rewrite" url="/Jetcar/Homepage.aspx" appendQueryString="true" /> </rule>
The URL that we want match is after the Virtual Directory(Jetcar).
For this code:
<rule name="MyRole" stopProcessing="true"> <match url="Home/(.*)" /> <action type="Rewrite" url="/{R:1}" appendQueryString="true" /> </rule>
It is incorrect that If you want type the folder name(Home).
As my previous's reply you can use the rewriteMaps if you want match the Virtual Directory.
Please refer to this code below:
<system.webServer> <rewrite> <rewriteMaps> <rewriteMap name="HomeRewrite"> <add key="/Jetcar/Homepage.aspx" value="/Jetcar/Home/Homepage.aspx" /> </rewriteMap> </rewriteMaps> <rules> <!-- <rule name="Rewrite rule1 for HomeRewrite"> <match url=".*" /> <conditions> <add input="{HomeRewrite:{REQUEST_URI}}" pattern="(.+)" /> </conditions> <action type="Rewrite" url="{C:1}" appendQueryString="false" /> </rule> --> <!--Or--> <rule name="mubinaRule" stopProcessing="true"> <match url="^Homepage.aspx" /> <conditions> <add input="{HTTP_HOST}" pattern="^www.starain.com$" /> </conditions> <action type="Rewrite" url="Home/Homepage.aspx" /> </rule> </rules> </rewrite> </system.webServer>
If you still have the issue, I suggest that you can share your project in the SkyDrive, then we can provide the furture suggestions.
Thanks
Best Regards
Wednesday, September 25, 2013 12:00 AM -
User-1199691179 posted
see below rule for converting URL to Lower case is running proper
<rule name="Lower Case URLs" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>but above your code is not give me Result that what i want .
Wednesday, September 25, 2013 1:33 AM -
User1508394307 posted
but above your code is not give me Result that what i wantSorry, again not clear, what did you typed, what was the result and what did you expect to get?
Wednesday, September 25, 2013 2:08 AM -
User-1454326058 posted
Hi rahul,
<rule name="Lower Case URLs" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>This rule is correct.
but above your code is not give me Result that what i want .Please provide the detail information that why that code isn't work.
On the other hand, could you share your project to me?
Thanks
Best Regards
Wednesday, September 25, 2013 4:20 AM -
User-1199691179 posted
Please see the belows code for Test project :
I want URL http://localhost:2735/TestURL/Default.aspx
Instate of http://localhost:2735/TestURL/Home/Default.aspx
I want to Remove Home folder from URL ,
so please tell me what code should i required write in
web.config inside Rewrite Rule.
Friday, September 27, 2013 12:15 AM -
User-1454326058 posted
Hi,
Please try this:
<system.webServer> <rewrite> <!-- <rewriteMaps> <rewriteMap name="HomeRewrite"> <add key="/TestURL/Default.aspx" value="/TestURL/Home/Default.aspx" /> </rewriteMap> </rewriteMaps> <rules> <rule name="Rewrite rule1 for HomeRewrite"> <match url=".*" /> <conditions> <add input="{HomeRewrite:{REQUEST_URI}}" pattern="(.+)" /> </conditions> <action type="Rewrite" url="{C:1}" appendQueryString="false" /> </rule> --> <!--Or--> <rule name="Testurl" stopProcessing="true"> <match url="^Default.aspx" /> <conditions> <add input="{HTTP_HOST}" pattern="^localhost:2735$" /> </conditions> <action type="Rewrite" url="Home/Default.aspx" /> </rule> </rules> </rewrite>
If you type http://localhost:2735/TestURL/Default.aspx it will rewrite to http://localhost:2735/TestURL/Home/Default.aspx.
If you still have the issue, please share your project to me.
Thanks
Best Regard
Friday, September 27, 2013 5:36 AM -
User-1199691179 posted
How can i get URL like http://10.1.0.15/TestURL for home page only
instead of http://10.1.0.15/TestURL/Homepage.aspx
please Help.............................
Saturday, September 28, 2013 1:23 AM -
User-1454326058 posted
Hi rahul,
Please try to use this code:
<rewriteMaps> <rewriteMap name="HomeRewrite"> <add key="/TestURL" value="/TestURL/Homepage.aspx" /> </rewriteMap> </rewriteMaps> <rules> <rule name="Rewrite rule1 for HomeRewrite"> <match url=".*" /> <conditions> <add input="{HomeRewrite:{REQUEST_URI}}" pattern="(.+)" /> </conditions> <action type="Rewrite" url="{C:1}" appendQueryString="false" /> </rule> </rules>
Thanks
Best Regards
Saturday, September 28, 2013 5:43 AM