943,925 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 9118
  • ASP.NET RSS
Apr 2nd, 2008
0

301 redirect on a non-aspx page?

Expand Post »
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!
Similar Threads
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Apr 2nd, 2008
-1

Re: 301 redirect on a non-aspx page?

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
cstock is offline Offline
1 posts
since Apr 2008
Apr 2nd, 2008
1

Re: 301 redirect on a non-aspx page?

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
ASP.NET Syntax (Toggle Plain Text)
  1. <location path="test.htm">
  2. <system.webServer>
  3. <httpRedirect enabled="true" destination="http://test.com/test.aspx" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
  4. </system.webServer>
  5. </location>
Last edited by peter_budo; Apr 4th, 2008 at 5:47 am. Reason: Keep It Organized - please use [code] tags
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Apr 3rd, 2008
0

Re: 301 redirect on a non-aspx page?

Click to Expand / Collapse  Quote originally posted by plazmo ...
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 1:08 pm.
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Apr 3rd, 2008
1

Re: 301 redirect on a non-aspx page?

Click to Expand / Collapse  Quote originally posted by SelArom ...
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.
ASP.NET Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <system.web>
  4. <--...other configs...-->
  5. </system.web>
  6. <location path="test.htm">
  7. <system.webServer>
  8. <httpRedirect enabled="true" destination="http://mini-server.dyndns.ws/" exactDestination="true" childOnly="true" httpResponseStatus="Permanent" />
  9. </system.webServer>
  10. </location>
  11. </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 3:28 pm.
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Apr 3rd, 2008
0

Re: 301 redirect on a non-aspx page?

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
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Apr 3rd, 2008
1

Re: 301 redirect on a non-aspx page?

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!
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Jul 30th, 2010
0
Re: 301 redirect on a non-aspx page?
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
Last edited by Ezzaral; Jul 30th, 2010 at 8:17 pm. Reason: Changed link to generic.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
GamersX is offline Offline
2 posts
since Jul 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to get value of selected dynamic checkboxes?
Next Thread in ASP.NET Forum Timeline: How To Pull Values From Inner Html Attached Radio Buttons





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC