URL Re-write question

Discussion in 'ASP .Net' started by Med, Aug 6, 2008.

  1. Med

    Med Guest

    Hi,

    From
    http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html I
    managed to rewrite
    http://www.example.com/product.aspx?productname=Panasonic TV to:
    http://www.example.com/Panasonic-TV-123.aspx

    I am new to URL re-write and I have couple of questions:


    1. As far as search engines such as google are concerned, does file
    extension in URL matter? If so How can I change Panasonic-TV-123.aspx to
    Panasonic-TV-123.html?
    2. At the moment All my aspx files in my public app folder are URL
    re-written to page2.aspx due to my web.config setting as follow:
    <rewriter>
    <rewrite url="~/public/(.+)-(.+).aspx"
    to="~/public/page2.aspx?MyTitleId=$2"/>
    </rewriter>

    How can I change the url re-write destination individually for each aspx
    page as follow:

    <rewrite url="~/public/page1.aspx" to="~/public/page2.aspx?MyTitleId=$2"/>
    <rewrite url="~/public/page3.aspx" to="~/public/page4.aspx?MyTitleId=$2"/>
    .....
    but when I try to load page1.aspx it loads page2.aspx

    Thanks for your time.

    Med
     
    Med, Aug 6, 2008
    #1
    1. Advertising

  2. Med

    Guest

    On 6 août, 15:41, "Med" <> wrote:
    > Hi,
    >
    > Fromhttp://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriter....I
    > managed to rewritehttp://www.example.com/product.aspx?productname=Panasonic+TV to:http://www.example.com/Panasonic-TV-123.aspx
    >
    > I am new to URL re-write and I have couple of questions:
    >
    > 1. As far as search engines such as google are concerned, does file
    > extension in URL matter?  If so How can I change Panasonic-TV-123.aspx to
    > Panasonic-TV-123.html?
    > 2. At the moment All my aspx files in my public app folder are URL
    > re-written to page2.aspx due to my web.config setting as follow:
    > <rewriter>
    >     <rewrite url="~/public/(.+)-(.+).aspx"
    > to="~/public/page2.aspx?MyTitleId=$2"/>
    > </rewriter>
    >
    > How can I change the url re-write destination individually for each aspx
    > page as follow:
    >
    > <rewrite url="~/public/page1.aspx" to="~/public/page2.aspx?MyTitleId=$2"/>
    > <rewrite url="~/public/page3.aspx" to="~/public/page4.aspx?MyTitleId=$2"/>
    > ....
    > but when I try to load page1.aspx it loads page2.aspx
    >
    > Thanks for your time.
    >
    > Med


    1) No, it doesn't (it's an old seo myth).

    2) I'm not sure about how your site is set up, but you're supposed to
    rewrite a non-existing path (a fancy one, like www.mysite.com/myfancyname)
    into a real one (www.mysite.com/page2.aspx?bla=bla). So, in your case,
    it is normal that page2 is loaded. I don't exactly understand what you
    are trying to achieve, i.e., what is the fancy name and what is the
    real page that the fancy name is supposed to redirect to ?

    Personally, I use HttpApplication.Context.RewritePath inside the
    Application_BeginRequest event, and then carry over any useful info
    through HttpApplication.Context.Items into the
    Application_AcquireRequestState event. But I have to support
    multilingual sites, so it's probably overkill in your case.

    Michel
     
    , Aug 7, 2008
    #2
    1. Advertising

  3. Med

    Med Guest

    Hi Michel,

    Thanks for replying.
    > I don't exactly understand what you are trying to achieve.

    As you may know the rewrite expression element in web.config <rewrite
    url="~/public/(.+)-(.+).aspx"> to="~/public/page2.aspx?MyTitleId=$2"/>
    re-writes all aspx files in "public" folder to page2.aspx. In
    ="~/public/page1.aspx" I have a method that creates a file name i.e.
    "Panasonic-TV-123.aspx" and I assign this to a hyperlink "NavigateUrl"
    property i.e
    Hyperlink1.NavigateUrl=SeoUrlGenerator.GenerateURL("Panasonic-TV", "123");.
    So hyperlink navigates to http://localhost/public/Panasonic-TV-123.aspx and
    I can get the post/get values in page2.aspx Load event.

    Now imagine a scenario that I have page3.aspx in same "public" folder and it
    has a similar hyperlink, but I want to navigate and process it (get post/get
    values in Load event) in "page4.aspx" and NOT "page2.aspx". But due to the
    rewrite expression element in web.config it re-writes all aspx files in
    "public" folder to Page2.aspx. I am aware that by putting aspx files in
    seperate folder instead of "public" folder and add an expression for each
    folder in web.config, I can achive this, but I end-up with seperate folder
    for each aspx file!

    I hope that I am making sence here.


    Regards


    Med

    <> wrote in message
    news:...
    On 6 août, 15:41, "Med" <> wrote:
    > Hi,
    >
    > Fromhttp://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriter...I
    > managed to
    > rewritehttp://www.example.com/product.aspx?productname=Panasonic+TV
    > to:http://www.example.com/Panasonic-TV-123.aspx
    >
    > I am new to URL re-write and I have couple of questions:
    >
    > 1. As far as search engines such as google are concerned, does file
    > extension in URL matter? If so How can I change Panasonic-TV-123.aspx to
    > Panasonic-TV-123.html?
    > 2. At the moment All my aspx files in my public app folder are URL
    > re-written to page2.aspx due to my web.config setting as follow:
    > <rewriter>
    > <rewrite url="~/public/(.+)-(.+).aspx"
    > to="~/public/page2.aspx?MyTitleId=$2"/>
    > </rewriter>
    >
    > How can I change the url re-write destination individually for each aspx
    > page as follow:
    >
    > <rewrite url="~/public/page1.aspx" to="~/public/page2.aspx?MyTitleId=$2"/>
    > <rewrite url="~/public/page3.aspx" to="~/public/page4.aspx?MyTitleId=$2"/>
    > ....
    > but when I try to load page1.aspx it loads page2.aspx
    >
    > Thanks for your time.
    >
    > Med


    1) No, it doesn't (it's an old seo myth).

    2) I'm not sure about how your site is set up, but you're supposed to
    rewrite a non-existing path (a fancy one, like www.mysite.com/myfancyname)
    into a real one (www.mysite.com/page2.aspx?bla=bla). So, in your case,
    it is normal that page2 is loaded. I don't exactly understand what you
    are trying to achieve, i.e., what is the fancy name and what is the
    real page that the fancy name is supposed to redirect to ?

    Personally, I use HttpApplication.Context.RewritePath inside the
    Application_BeginRequest event, and then carry over any useful info
    through HttpApplication.Context.Items into the
    Application_AcquireRequestState event. But I have to support
    multilingual sites, so it's probably overkill in your case.

    Michel
     
    Med, Aug 7, 2008
    #3
  4. Med

    Guest

    On 7 août, 15:21, "Med" <> wrote:
    > Hi Michel,
    >
    > Thanks for replying.> I don't exactly understand what you are trying to achieve.
    >
    > As you may know the rewrite expression element in web.config <rewrite
    > url="~/public/(.+)-(.+).aspx"> to="~/public/page2.aspx?MyTitleId=$2"/>
    > re-writes all aspx files in "public" folder to page2.aspx.  In
    > ="~/public/page1.aspx" I have a method that creates a file name i.e.
    > "Panasonic-TV-123.aspx" and I assign this to a hyperlink "NavigateUrl"
    > property i.e
    > Hyperlink1.NavigateUrl=SeoUrlGenerator.GenerateURL("Panasonic-TV", "123");.
    > So hyperlink navigates tohttp://localhost/public/Panasonic-TV-123.aspxand
    > I can get the post/get values in page2.aspx Load event.
    >
    > Now imagine a scenario that I have page3.aspx in same "public" folder and it
    > has a similar hyperlink, but I want to navigate and process it (get post/get
    > values in Load event) in "page4.aspx" and NOT "page2.aspx". But due to the
    > rewrite expression element in web.config it re-writes all aspx files in
    > "public" folder to Page2.aspx.  I am aware that by putting aspx files in
    > seperate folder instead of "public" folder and add an expression for each
    > folder in web.config, I can achive this, but I end-up with seperate folder
    > for each aspx file!
    >
    > I hope that I am making sence here.
    >
    > Regards
    >
    > Med
    >
    > <> wrote in message
    >
    > news:...
    > On 6 août, 15:41, "Med" <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > Fromhttp://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriter...
    > > managed to
    > > rewritehttp://www.example.com/product.aspx?productname=Panasonic+TV
    > > to:http://www.example.com/Panasonic-TV-123.aspx

    >
    > > I am new to URL re-write and I have couple of questions:

    >
    > > 1. As far as search engines such as google are concerned, does file
    > > extension in URL matter? If so How can I change Panasonic-TV-123.aspx to
    > > Panasonic-TV-123.html?
    > > 2. At the moment All my aspx files in my public app folder are URL
    > > re-written to page2.aspx due to my web.config setting as follow:
    > > <rewriter>
    > > <rewrite url="~/public/(.+)-(.+).aspx"
    > > to="~/public/page2.aspx?MyTitleId=$2"/>
    > > </rewriter>

    >
    > > How can I change the url re-write destination individually for each aspx
    > > page as follow:

    >
    > > <rewrite url="~/public/page1.aspx" to="~/public/page2.aspx?MyTitleId=$2"/>
    > > <rewrite url="~/public/page3.aspx" to="~/public/page4.aspx?MyTitleId=$2"/>
    > > ....
    > > but when I try to load page1.aspx it loads page2.aspx

    >
    > > Thanks for your time.

    >
    > > Med

    >
    > 1) No, it doesn't (it's an old seo myth).
    >
    > 2) I'm not sure about how your site is set up, but you're supposed to
    > rewrite a non-existing path (a fancy one, likewww.mysite.com/myfancyname)
    > into a real one (www.mysite.com/page2.aspx?bla=bla). So, in your case,
    > it is normal that page2 is loaded. I don't exactly understand what you
    > are trying to achieve, i.e., what is the fancy name and what is the
    > real page that the fancy name is supposed to redirect to ?
    >
    > Personally, I use HttpApplication.Context.RewritePath inside the
    > Application_BeginRequest event, and then carry over any useful info
    > through HttpApplication.Context.Items into the
    > Application_AcquireRequestState event. But I have to support
    > multilingual sites, so it's probably overkill in your case.
    >
    > Michel- Masquer le texte des messages précédents -
    >
    > - Afficher le texte des messages précédents -


    Ok, I think it's a bit clearer now. I think you won't be able to avoid
    a correspondance table somewhere. The easiest way I can see from your
    setup is to simply programmatically edit the web.config file, adding
    lines each time you add a new product :

    <rewrite url="~/public/panasonictv-123.aspx" to="~/public/page2.aspx?
    MyTitleId=$2"/>
    <rewrite url="~/public/sonytv-123.aspx" to="~/public/page4.aspx?
    MyTitleId=$2"/>

    ...and so on. You can write to the config file programmatically
    through the WebConfigurationManager class :
    http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager.aspx

    If you plan to have lots of products, it might be better to store the
    correspondances between rewritten urls and actual page names in a DB,
    in which case you'll need to rewrite the Url inside the
    Application_BeginRequest event handler, or roll your own HttpHandler
    (http://codebetter.com/blogs/jeffrey.palermo/archive/
    2005/08/10/130532.aspx).

    You could also work on the regex expression and add a special tag to
    your rewritten Urls, like if there is "panasonic" in the Urls you
    redirect it to page2.aspx, if there is "sony" you redirect to
    page4.aspx, and so on...

    HTH,

    Michel
     
    , Aug 7, 2008
    #4
  5. Med

    Med Guest

    Thanks Michel.I'll give a try.

    Regards

    Med

    <> wrote in message
    news:...
    On 7 août, 15:21, "Med" <> wrote:
    > Hi Michel,
    >
    > Thanks for replying.> I don't exactly understand what you are trying to
    > achieve.
    >
    > As you may know the rewrite expression element in web.config <rewrite
    > url="~/public/(.+)-(.+).aspx"> to="~/public/page2.aspx?MyTitleId=$2"/>
    > re-writes all aspx files in "public" folder to page2.aspx. In
    > ="~/public/page1.aspx" I have a method that creates a file name i.e.
    > "Panasonic-TV-123.aspx" and I assign this to a hyperlink "NavigateUrl"
    > property i.e
    > Hyperlink1.NavigateUrl=SeoUrlGenerator.GenerateURL("Panasonic-TV",
    > "123");.
    > So hyperlink navigates tohttp://localhost/public/Panasonic-TV-123.aspxand
    > I can get the post/get values in page2.aspx Load event.
    >
    > Now imagine a scenario that I have page3.aspx in same "public" folder and
    > it
    > has a similar hyperlink, but I want to navigate and process it (get
    > post/get
    > values in Load event) in "page4.aspx" and NOT "page2.aspx". But due to the
    > rewrite expression element in web.config it re-writes all aspx files in
    > "public" folder to Page2.aspx. I am aware that by putting aspx files in
    > seperate folder instead of "public" folder and add an expression for each
    > folder in web.config, I can achive this, but I end-up with seperate folder
    > for each aspx file!
    >
    > I hope that I am making sence here.
    >
    > Regards
    >
    > Med
    >
    > <> wrote in message
    >
    > news:...
    > On 6 août, 15:41, "Med" <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > Fromhttp://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriter...
    > > managed to
    > > rewritehttp://www.example.com/product.aspx?productname=Panasonic+TV
    > > to:http://www.example.com/Panasonic-TV-123.aspx

    >
    > > I am new to URL re-write and I have couple of questions:

    >
    > > 1. As far as search engines such as google are concerned, does file
    > > extension in URL matter? If so How can I change Panasonic-TV-123.aspx to
    > > Panasonic-TV-123.html?
    > > 2. At the moment All my aspx files in my public app folder are URL
    > > re-written to page2.aspx due to my web.config setting as follow:
    > > <rewriter>
    > > <rewrite url="~/public/(.+)-(.+).aspx"
    > > to="~/public/page2.aspx?MyTitleId=$2"/>
    > > </rewriter>

    >
    > > How can I change the url re-write destination individually for each aspx
    > > page as follow:

    >
    > > <rewrite url="~/public/page1.aspx"
    > > to="~/public/page2.aspx?MyTitleId=$2"/>
    > > <rewrite url="~/public/page3.aspx"
    > > to="~/public/page4.aspx?MyTitleId=$2"/>
    > > ....
    > > but when I try to load page1.aspx it loads page2.aspx

    >
    > > Thanks for your time.

    >
    > > Med

    >
    > 1) No, it doesn't (it's an old seo myth).
    >
    > 2) I'm not sure about how your site is set up, but you're supposed to
    > rewrite a non-existing path (a fancy one, likewww.mysite.com/myfancyname)
    > into a real one (www.mysite.com/page2.aspx?bla=bla). So, in your case,
    > it is normal that page2 is loaded. I don't exactly understand what you
    > are trying to achieve, i.e., what is the fancy name and what is the
    > real page that the fancy name is supposed to redirect to ?
    >
    > Personally, I use HttpApplication.Context.RewritePath inside the
    > Application_BeginRequest event, and then carry over any useful info
    > through HttpApplication.Context.Items into the
    > Application_AcquireRequestState event. But I have to support
    > multilingual sites, so it's probably overkill in your case.
    >
    > Michel- Masquer le texte des messages précédents -
    >
    > - Afficher le texte des messages précédents -


    Ok, I think it's a bit clearer now. I think you won't be able to avoid
    a correspondance table somewhere. The easiest way I can see from your
    setup is to simply programmatically edit the web.config file, adding
    lines each time you add a new product :

    <rewrite url="~/public/panasonictv-123.aspx" to="~/public/page2.aspx?
    MyTitleId=$2"/>
    <rewrite url="~/public/sonytv-123.aspx" to="~/public/page4.aspx?
    MyTitleId=$2"/>

    ....and so on. You can write to the config file programmatically
    through the WebConfigurationManager class :
    http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager.aspx

    If you plan to have lots of products, it might be better to store the
    correspondances between rewritten urls and actual page names in a DB,
    in which case you'll need to rewrite the Url inside the
    Application_BeginRequest event handler, or roll your own HttpHandler
    (http://codebetter.com/blogs/jeffrey.palermo/archive/
    2005/08/10/130532.aspx).

    You could also work on the regex expression and add a special tag to
    your rewritten Urls, like if there is "panasonic" in the Urls you
    redirect it to page2.aspx, if there is "sony" you redirect to
    page4.aspx, and so on...

    HTH,

    Michel
     
    Med, Aug 7, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon paugh
    Replies:
    1
    Views:
    960
  2. =?Utf-8?B?QWJlbCBDaGFu?=
    Replies:
    6
    Views:
    9,532
    Rahul
    May 3, 2006
  3. Peter Hansen
    Replies:
    1
    Views:
    412
    Joona I Palaste
    Aug 24, 2003
  4. JasBascom
    Replies:
    1
    Views:
    376
    John Harrison
    Feb 24, 2004
  5. Just D.
    Replies:
    0
    Views:
    559
    Just D.
    Aug 11, 2004
Loading...

Share This Page