hello, I'm in the process of upgrading a site's pages from htm static content to a dynamix aspx page. the problem is that I want to redirect users visiting the old pages to the new pages and I want to use the proper 301 "moved permanently" redirect to be search engine-friendly. Unfortunately I can't figure out any way to do this! the extension is htm, so I can't embed any server-side scripting to redirect the user and change the response code...

I know I can do a meta or javascript refresh but that's not the proper way to do it. I tried doing a redirect in IIS but I could only redirect a folder, not an individual file (this is IIS 7 by the way).

I thought maybe I could force asp.net to handle the htm extension and inject the redirect code that way but I couldn't figure out how to do it properly. Is there any other way to do a 301 redirect without using server side scripting or htaccess? I seem to be stuck and will probably just have to do the meta refresh

any help is appreciated, thank you!

Recommended Answers

All 7 Replies

By using 301 redirects your site won't be search engine friendly. 301s will help you transfer pagerank from existing pages to new ones. But if the new URLs are in the form of index.asp?a=this&b=that&z=blah, then google won't be that happy.

So if you currently have structured URLs you better keep your existing urls by doing internal URL rewriting such as

/this/that/blah.htm to /index.asp?a=this&b=that&z=blah

or if no strucured URLs exist, create a new structured URL schema, redirect old urls to new structured ones, and rewrite the structured ones to the real .asp url. For example:

Redirect /goofy.htm to /this/that/blah.htm

and

Rewrite /this/that/blah.htm to /index.asp?a=this&b=that&z=blah

This way both your visitors and google will be happy. The most effective way to do such rewriting/redirection stuff is using a tool like Apache mod_rewrite and .htaccess. The best tool I know for IIS is IIS Mod-Rewrite Pro, but you can also find more tools at this wikipedia entry. All you need is a script like this:

RewriteEngine On
RewriteRule ^goofy.htm$ /this/that/blah.htm [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.htm$ /index.asp?a=$1&b=$2&z=$3 [L]

But for god's sake don't use meta refresh tags or client side scripts if you want to save your precious existing pagerank.

You should set this up in IIS using an http redirect.
You just need to have the file highlighted then in features view select http redirect then specify the new address in the box and check the two options for exact location and not the subdir and select the return code. and that should work


edit:
this is what it creates in your web.config

<location path="test.htm">
        <system.webServer>
            <httpRedirect enabled="true" destination="http://test.com/test.aspx" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
        </system.webServer>
    </location>

You should set this up in IIS using an http redirect.
You just need to have the file highlighted then in features view select http redirect then specify the new address in the box and check the two options for exact location and not the subdir and select the return code. and that should work


edit:
this is what it creates in your web.config
<location path="test.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://test.com/test.aspx" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
</system.webServer>
</location>

thank you for your reply! would it be possible just to put this in the web.config file for each page and be done with it? or do I have to do something in IIS to make it work?

EDIT: okay I tried it in the web.config and it didn't work. I tried to follow your IIS instructions, but after highlighting the file and switching to Features View, there is no entry for httpredirect. is there something else I need to enable? thanks!

thank you for your reply! would it be possible just to put this in the web.config file for each page and be done with it? or do I have to do something in IIS to make it work?

EDIT: okay I tried it in the web.config and it didn't work. I tried to follow your IIS instructions, but after highlighting the file and switching to Features View, there is no entry for httpredirect. is there something else I need to enable? thanks!

the web.config needs to be at the root of your old site.
looks like this fully written out.
This can be entered as many times as you need, im not sure if there is an easier way to write it though.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
<--...other configs...-->
  </system.web>
    <location path="test.htm">
        <system.webServer>
            <httpRedirect enabled="true" destination="http://mini-server.dyndns.ws/" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
        </system.webServer>
    </location>
</configuration>

im not sure why your not seeing http redirect.
try going to content view then right clicking on the file and select feature view.
it will say: filename.htm Home instead of WebsiteName Home at the top of the feature view.
the option is under the IIS group in the features view.

thanks again for the reply, I tried as you suggested, right-clicking and selecting features view, it does work as you described, showing the file instead of the website, but there is still no option to add a redirect. I would imagine that this is the reason it isn't working even when I add the code manually to web.config. Is there an option I need to be checking that enables redirects site-wide?

many thanks

What would the code look like to direct a subdomain to a given loacation? Like http://s1.domain.com to http://www.example.com. I have seen it out there. Thanks, GamersX

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.