Solved

IIS 7 URL Rewrite failing if original file had a space

Posted on 2011-09-30
8
1,545 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

751 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