Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IIS 7 URL Rewrite failing if original file had a space

Posted on 2011-09-30
8
Medium Priority
?
1,707 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here are the symptoms: You start receiving calls from users that one of your legacy web apps isn't coming up, so you log into your IIS 5 server to check it out.  When you pull up the services, you notice that the WWW Publishing service isn't runn…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

876 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