Solved

IIS 7 URL Rewrite failing if original file had a space

Posted on 2011-09-30
8
1,599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I came across an interesting issue that had me pulling my hair out.  I was troubleshooting a new internal web site which uses integrated security instead of anonymous.  When browsing the site from my laptop, I was able to access it with no iss…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 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