Solved

IIS 7 URL Rewrite failing if original file had a space

Posted on 2011-09-30
8
1,374 Views
Last Modified: 2012-08-13
I am doing an URL rewrite. They work fine except if the original file name had a space.
None of these work. Can someone tell me the correct syntax?

<add key="/My%20Page.htm" value="http://www.mynewsite.com/about/newpage.htm" />
<add key="/My\sPage.htm" value="...
<add key="/My\ Page.htm" value="...
0
Comment
Question by:EndeavorToPersevere
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:AlokJain0412
ID: 36895953
Hi
See this helpful link regarding Rewrite rule
http://cheeso.members.winisp.net/Iirf20Help/html/bdaf0dbe-e539-4bf5-9231-1dae3b0e27a5.htm
---
You can include spaces and ampersands and other special characcters in the replacement string by URL-escaping them. For example, to include a space in a replacement string, you would use %%20.
Example 8:
Copy
RewriteRule  ^/downloads/myapp.exe /downloads/myapp%%201.2.exe
The above rule would rewrite an incoming request for myapp.exe to "myapp 1.2.exe"
For more on this, in the tests directory, see the SpacesInReplacementString sub-directory.

If its not you Please redefine your question more specifically
0
 
LVL 2

Author Comment

by:EndeavorToPersevere
ID: 36898323
Hopefully this is clearer. I have this in my web.config file

      <rewrite>
        <rewriteMaps>
          <rewriteMap name="My 301 Redirects">
            <add key="/careers.aspx" value="http://www.newsite.com/about/careers.aspx" />
            <add key="/Newsletter/Newsletter%20Q2%202010.htm" value="http://www.newsite.com/About/News.aspx" />
          </rewriteMap>
        </rewriteMaps>
	  <rules>
		  <rule name="Redirect rule1 for My 301 Redirects">
			  <match url=".*" />
			  <conditions>
				  <add input="{My 301 Redirects:{REQUEST_URI}}" pattern="(.+)" />
			  </conditions>
			  <action type="Redirect" url="{C:1}" appendQueryString="false" />
		  </rule>
           </rules>
        </rewrite>

Open in new window


All of the pages which do Not have a space in the original URL work correctly. All of the pages which Do have a space in the original URL fail the redirect.

I have tried using \ and \s in place of the %20 but they do not work either. I have not figured out what the correct syntax for the original page's URL should be when it has a space in the name. I am currently using %20 in place of the space but that is not working.
0
 
LVL 5

Expert Comment

by:AlokJain0412
ID: 36899171
Hi although its not concluding suggestion but

1. You please read this thread and think it give you idea to solve your problem
http://forums.asp.net/t/1130676.aspx/1
2.If you are using appache ,This Link http://www.aitechsolutions.net/apacheredirect.html  tell
NOTE: If you have spaces in the source URL you wish to redirect, then enclose the URL in double quotes like this: Redirect 301 "/my script.pl" http://my.server.com/myscript.php

can you tell ne which version of IIS you are using
0
 
LVL 2

Author Comment

by:EndeavorToPersevere
ID: 36901288
Thanks for the ideas. I read the thread. I can't rename the original pages because the point is to redirect them to the new site without breaking any existing links to those pages on our old site.

This is a Microsoft windows server running IIS 7 not Apache.

Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:AlokJain0412
ID: 36901822

If you have few Pages you can use
Native URL mapping in ASP.NET 2.0
Like that
new urlMappings section within the system.web section of your web.config file and add the required mappings (the path ~/ points to the root directory of the web application):

<urlMappings enabled="true">
   <add url="~/Info/Copyright.aspx" mappedUrl="~/Help/Copyright.aspx" />
   <add url="~/Support/Contacts.aspx" mappedUrl="~/Help/Contacts.aspx" />
</urlMappings>

Thus, if a user types http://www.somebloghost.com/Support/Contacts.aspx, he can then see the page located at http://www.somebloghost.com/Help/Contacts.aspx, without even knowing the page had been moved.
0
 
LVL 17

Accepted Solution

by:
Rovastar earned 250 total points
ID: 36902522
Your rules looks a little odd but I haven't used the rewrite maps for a while.

Firstly, get back to basics does the non-mapped rule work ok for you?

I have success with just adding a space in space in the match URL. Have you tried that? You don't state if you actually tried it with a space.

 <rule name="test3">
                    <match url="my page.aspx" />
                    <action type="Redirect" url="http://www.mytest.com" />
  </rule>  

Other than that follow it through the failed request tracing for this rule what does it say when it tries to execute the rewrite rule in question. Does it succeed or failed the pattern match, etc?
0
 
LVL 2

Author Comment

by:EndeavorToPersevere
ID: 36905509
The non-mapped rule works fine. The mapped rule works fine except for the pages that have a space.

I tried changing the %20 to a space but that didn't work either.

I'll take a look at the tracing.

Thanks.
0
 
LVL 2

Author Comment

by:EndeavorToPersevere
ID: 36916610
It was supposed to be a space not %20 in the web.config. What I also needed to do before testing this was restart the site in IIS so the new web.config would kick in.

Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Debug Tools to analyse IIS process: This article focus on taking memory dumps from IIS to determine which code is taking more time and to analyse which calls hangs/causes more CPU usage. To take dumps,download the following. Install1: To st…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now