URL Re-write question

M

Med

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
 
M

michel.desangles

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
 
M

Med

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

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
 
M

michel.desangles

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











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
 
M

Med

Thanks Michel.I'll give a try.

Regards

Med

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











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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top