URL re-writing?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 年 前
Hey chaps :)

I am replacing an old site with a nopCommerce solution (nearly done!)

And will be making my own 301 handler for the majority of the old pages...

However the most requested pages from the old site, I want to include in the URL re-writer...

This is so that those URL's still "exist" send send back relavent data without sending back a 301 to the search engines...


I tried adding a virtual URL and destination URL to UrlRewriting.config but it didn't work :(

    <add name="MyRewriteRule" virtualUrl="~/directory/oldfile.htm"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/products/product.aspx"
         ignoreCase="true" />

Any ideas? :)    Help would be hugely appreciated...

I'm gonna add my site to "show off" once it's done...   It's hugely modified from the nopCommerce default, so will be purchasing a license as it goes online :)
14 年 前
xerath wrote:


virtualUrl="~/directory/oldfile.htm"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/products/product.aspx"
         ignoreCase="true" />



This rewriter works only with .aspx extensions, and you have .htm extension. If you use IIS 7 (and integrated pipeline) then maybe you can make it work by adding to web.config

<system.webServer>
  ...
    <modules runAllManagedModulesForAllRequests="true">
    ...
        </modules>
    ...
  </system.webServer>
  <runtime>
  ...
        <modules runAllManagedModulesForAllRequests="true">
            <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
            ...
        </modules>
        ...
  </runtime>


replace ... with the code that was there before
14 年 前
thanks dude will try that :)
14 年 前
Didn't have any luck with that I'm afraid :(


Although results were interesting!!


When I added;

    <modules runAllManagedModulesForAllRequests="true">


and typed a page that doesnt exist..

mywebsite.com/qrijqoirhjwqorj

I get an ASP 404 error page listing the requested page as Requested URL: /qrijqoirhjwqorj/default.aspx

(even though I requested qrijqoirhjwqorj and not qrijqoirhjwqorj/)



Anyway here's the interesting bit...  When I request my .htm which I added to my URL re-writer config file..

Requested URL: /Products/myproduct.aspx

it DOES actually say it's reqeusting the CORRECT URL as per my config file... however, it still throws a 404..

I am assuming the URL re-writer has done it's job...  but then the URL it's tried to send doesn't exist because it's trying to re-write to a re-write...


Blimey
14 年 前
sorry i'm such a muppet!

I've put in the re-direct URL as the non-seo link which the URL re-writer actually creates for products...

and that works! :)
14 年 前
So everything Okay now?
14 年 前
This is about to get a whole lot more complicated I think but if I can crack it I'll be happy!    I want to make this an interesting and useful thread for others too!

OK...

If you set ALL requests to go through the URL handler then type in something which doesn't exist;
eg/ www.mysite.com/rwqqwerwer

you get a 404 returned for www.mysite.com/rwqqwerwer/default.aspx

When you visit the homepage you also get www.mysite.com/default.aspx in the address bar


So what I did was... I set it back to default... then in IIS I added a managed handler for *.htm, *.html requests which uses the URL re-writer...   So now if you type something which doesn't exist you get a proper 404 response.

Also if you type in a .htm request which is in the URL re-writing config file, it works!



The only problem I have now is this... if you type something which doesn't exist that has a .htm or .htm extension..

eg/ www.mysite.com/rewerewerw.htm

I get an  ASP error page saying "UrlRewriter does not implement IHttpHandlerFactory or IHttpHandler."

Basically, if the URL re-writing module doesn't have a rule so it throws an error...


Is there a way I can re-configure it so that EVERYTHING which doesn't exist that goes through the URL handler goes to my 404 page?

This would be awesome :)    As my 404 page is an ASP file with a 301 handler map...


The idea behind all this is basically...   the TOP requested pages from the old site get re-written so they still appear to exist..   and everything else goes to the 404 page which then 301's them to a new relavant location....   if nothing is found in the 301 handler then it FINALLY displays a 404 page.

I know it's a pain but SEO is paramount to this site!!   This way 404 pages will rarely be seen unless something doesn't exist on the current site, OR the old site.
14 年 前
GOT IT!!!

Sorry to bore you all with this crap... I've suceeded!!!

Summary...

If you want custom URL re-writing of .htm or other extensions...  add a custom handler using the URL re-writer in IIS7 for that extension

THEN add your URL re-write rules

FINALLY in IIS7 goto ASP.NET error pages... click "edit feature settings" and click "on" and enter your 404 handler on the absolute URL field.


My website now has this behaviour;

www.mysite.com/blahblahowifw    <--- 404 error

www.mysite.com/product/nopcommerceUrl.aspx   <----nop commerce pages working as normal

www.mysite.com/something/Poppular_content_page_from_old_site.htm   <---re-written to appropriate new page (still deemed to exist by search engines)

www.mysite.com/something/product_page_from_old_site.htm    <-- goes to 404.asp, where it returns a 301 to a new and relavant page

www.mysite.com/something/nonexistantpage.htm  <---  no re-write rule, goes to 404.asp where it finds no 301 either.. so displays a 404.
14 年 前
damn...

this isn't gonna work :(


.htm pages that don't exist... although they are appearing as a 404, they are sending a 500...

gotta rethink
14 年 前
How about not using the urlRewriter, but use native IIS7 Url mapper
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.