User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 426,893 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,367 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1359 | Replies: 6 | Solved
Reply
Join Date: Oct 2004
Posts: 48
Reputation: SelArom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Light Poster

301 redirect on a non-aspx page?

  #1  
Apr 2nd, 2008
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!
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 1
Reputation: cstock is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
cstock cstock is offline Offline
Newbie Poster

Re: 301 redirect on a non-aspx page?

  #2  
Apr 2nd, 2008
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.
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: 301 redirect on a non-aspx page?

  #3  
Apr 2nd, 2008
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>
Last edited by peter_budo : Apr 4th, 2008 at 4:47 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Oct 2004
Posts: 48
Reputation: SelArom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Light Poster

Re: 301 redirect on a non-aspx page?

  #4  
Apr 3rd, 2008
Originally Posted by plazmo View Post
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!
Last edited by SelArom : Apr 3rd, 2008 at 12:08 pm.
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: 301 redirect on a non-aspx page?

  #5  
Apr 3rd, 2008
Originally Posted by SelArom View Post
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.
Last edited by plazmo : Apr 3rd, 2008 at 2:28 pm.
Reply With Quote  
Join Date: Oct 2004
Posts: 48
Reputation: SelArom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Light Poster

Re: 301 redirect on a non-aspx page?

  #6  
Apr 3rd, 2008
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
Reply With Quote  
Join Date: Oct 2004
Posts: 48
Reputation: SelArom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Light Poster

Re: 301 redirect on a non-aspx page?

  #7  
Apr 3rd, 2008
aHA!! stumbled on this entry: http://blog.torresdal.net/2006/12/27...ectOnIIS7.aspx

turns out the damn thing wasn't installed! enabled it and it works like a charm!!

thanks for your help!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 10:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC