IIS 7 URL Rewrite failing if original file had a space

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="...
LVL 2
EndeavorToPersevereAsked:
Who is Participating?
 
RovastarConnect With a Mentor Commented:
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
 
AlokJain0412Commented:
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
 
EndeavorToPersevereAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
AlokJain0412Commented:
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
 
EndeavorToPersevereAuthor Commented:
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
 
AlokJain0412Commented:

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
 
EndeavorToPersevereAuthor Commented:
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
 
EndeavorToPersevereAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.