I'm probably going to use the URL rewrite module for IIS 7 eventually and I have a fairly straight forward question that I really can't find the answer to.
If you have a base case of:
http://yoururl.com/page.aspx?ID=7
You can obviously have it rewritten to:
http://yoururl.com/page/7 or whatever you want.
My question is this: When using this module can you still use Request.Querystring["page"] on the rewritten querystring. How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.
I would assume that your C#/asp.net code is completely unaffected by the url rewriting, as that's more or less the point, but I want to be crystal clear.
Secondary question: What is the best practice for how you should code a website when using the rewritten. Should you code links in the written style, or continue using querystrings?
When using this module can you still use Request.Querystring["page"] on the rewritten querystring.
Yes, you will be able to access the re-written QueryString in that way.
How does the Request.URL stuff work. Does asp.net still provide the un-rewritten url or does it provide the rewritten one.
Request.Url will be the re-written URL, but Request.RawUrl will be the original URL.
Should you code links in the written style, or continue using querystrings?
Yes, code your links in the way you want them to be seen by end users, and then in your code ensure you're aware of and document the changed format.
There is loads of information and tutorials on the IIS website here:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
Related
The real url is http://www.example.com/site.aspx?site=google.com
i want to the rewrite result more friendly.
like this: http://www.example.com/google.com
in C# code, i don't want to use third-party lib
only use RewritePath method or some code
I'm not sure I understand all of your requirements, but why couldn't you simply to a string.Replace(), or a regular expression if you could have other parameters in your query string as well.
There are some examples about how to rewrite, including this one.
You could also download the source code of URL Rewriter and see how the author does it.
Personally, I'm very satisfied with using URL Rewriter (binaries) in several of my projects.
I have implemented URL rewriting using Intelligencia, everything works perfectly.
now if i have an anchor i could do somenthig like
Test
with the seo friendly url olready in place
or do i have to do somenthing like
Test
public string GetSeoUrl(string url)
{
if(url == "../TestPage.aspx") return ../TestPage;
}
This will allow me to manage from a central location all the URLs.
I am working on .net 3.5 Web Form
But what are the implications of both approaches?Is it going to be slower?less efficient?is the right way to do it?
Thanks
I think second way is right way to do it. ( Managing from Central Location )
also,i don't think there will be any SEO implication using this as the final URL will be same but second one is rendred from server.
It might be littlebit slow but not noticable. as it runs some server code to generate url while first cenarion there won't be any processing.
I see you are using .NET, you can to do this already developed solution from ASP.NET MVC Framework called URL routing.
Read this http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
I would do the first one. The URL is the contract. Using the second approach may make you think that you can easily change the URL by updating the function. Changing the URL would cause seo issues.
This is the scenario: I have a list of about 5000 URLs which have already been published to various customers. Now, all of these URLs' location has changed on my server side. The server is still the same though. This is a ASP.NET website with .NET3.5/C#.
My requirement is : Though the customers use the older source URL they should be redirected to the new URL without any perceived change or intermediate redirection message etc.
I am trying to make sense of the whole scenario:
Where would I put the actual mapping of Old URL to New URL -- in a database or some config. file or is there a better option?
How would I actual implement a redirect:
Should I write a method with Server.Transfer ot Response.Redirect?
And is there a best practice to it like - placing the actual re-routing in HTTPModules..or is it Application_BeginRequest?
I am looking to achieve with a best-practice compliant methodology and very low performance degradation, if any.
If your application already uses a database then I'd use that. Make the old URL the primary key and lookups should be very fast. I'd personally wrap the whole thing in .NET classes that abstracts it and allow you to create a Dictionary<string,string> of all the URLs which can be loaded into memory from the DB and cached. This will be even faster.
Definitely DON'T use Server.Transfer. Instead you should do a 301 Permanently Moved redirect. This will let search engines know to use the new URL. If you were using NET 4.0 you could use the HttpResponse.RedirectPermanent method. However, in earlier versions you have to set the headers yourself - but this is trivial.
Keep the data in a database, but load into ASP.NET cache to reduce access time.
You definitely want to use HTTPModules. It's the accepted practice, and having recently tried to do it inside Global.asax, I can tell you that unless you want to do only the simplest kind of stuff (i.e. "~/mypage.aspx/3" <-> "~/mypage.aspx?param1=3) it's much more complicated and buggy than it seems.
In fact, I regret even trying to roll my own URL rewriting solution. It's just not worth it if you want something you can depend on. Scott Guthrie has a very good blog post on the subject, and he recommends UrlRewriter.net or UrlRewriting.net as a couple of free, open-source URL rewriting solutions.
Good luck.
My situation is. I have a project planned to be built on ASP.NET MVC 2. And one of the major requirements is SEO optimization. A customer wants to use static-like URLs that end up with .html extension for this project that make URLs more SEO friendly. E.g. "mysite.com/about.html " or "mysite.com/items/getitem/5.html" etc.
I wonder is there any benefit from SEO perspective to use .html extension in dynamic URLs? Are Google and other search engines rank work better with such URLs?
I would use sitemaps instead, this enables you to have dynamic content (and to use MVC) but still be crawled completely.
See: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184
and http://www.codinghorror.com/blog/2008/10/the-importance-of-sitemaps.html
No, the base URL doesn't matter. If you're serving dynamic content in .aspx or .html, it's all the same. If you do serve ASP.NET content with .html because of requirements (as dumb as they may be), then I suggest finding an alternative extension (e.g. .htm) for all static content. You don't want your static HTML files getting processed unnecessarily.
As Femaref said, you can use sitemaps to help.
Also, make sure your URL doesn't change (including variables) if the content is the same. This shouldn't be a problem with MVC.
Edit: In your example:
mysite.com/items/getitem/5.html
I'm guessing what you originally wanted is:
mysite.com/items/getitem/5
No extension doesn't make a difference either. Since that's not a problem, I would also argue that an extension makes the URL less "clean" and also suggests that there is a file called 5.html in that path, which is obviously not true.
Search engines don't care at all at what your webpage extensions look like.
If anything all you're doing indicating a file type for the page served up.
Can the page be reached?
Is there content?
Are there links pointing to that page?
That's what a search engine is worried about. Anyone can create a custom solution using custom file extensions for a website and have it work just fine.
I'm trying to use jQuery to make some AJAX calls, but because I have wild card mapping (to .NET) in IIS 6 turned on, it doesn't seem to work. Disabling the mapping makes everything magically work.
I've put the web method attribute on methods in both an .aspx page and an .asmx web service, but neither work. Here is the sample URL that I am using for the AJAX calls:
localhost/UserChecker.aspx/CheckIfUserEmailsExists
localhost/UserChecker.asmx/CheckIfUserEmailsExists
I figure it must be something with the way .NET is interpreting the URL's but I'm not entirely sure why. More importantly, I'm not sure how to fix it, other than to disable wild card mapping! Is there any other way???
UPDATE
The CMS I am using (Kentico) does some URL routing, but even if I skip over the routing in the global.asax.cs code, I still get a 404.
Thanks in advance!
With the wildcard mapping on IIS will run the initial request via the wildcard handler first. This will be done BEFORE any URL rewriting (or URL routing) by your CMS.
I think that is why you are getting 404.
You can also try to disable "verify file exists" checkbox on the wildcard mapping to cater for the scenario when the actual URL will be later rewritten to something else.
This is not a complete answer but I hope it points you in the direction of a solution.
Have you tried accessing the url directly in a browser and using some well placed breakpoints to track down the problem?
If you're getting 404s it sounds like your rules for routing aren't working.
[I'll update this if you can give a little more info about the behaviour you're seeing]
UPDATE
I think what might be happening is this:
You're providing a seperate mapping for your files with extensions (in these cases .aspx and .asmx):
localhost/UserChecker.aspx/CheckIfUserEmailsExists
localhost/UserChecker.asmx/CheckIfUserEmailsExists
These mappings are being used when you turn the wild card mappings off, and the '/CheckIfUserEmailsExists' is handled used or ignored.
When you turn on the wildcard mappings your routing isn't informing your app how to 'route' correctly.
If you removed the extensions (with wildcard mappings turned on) does the following work?
localhost/UserChecker/CheckIfUserEmailsExists
Add the appropriate URLs to the exclusion list: Use the "Excluded URLs" setting in the Site Manager->Settings tab. (basic help documentation)
I suggest checking the URl outside of your CMS framework; Issue has to be with the URL routing. No tsure how it was working without the wild card mapping.
Questions to understand:
1.Did you have your CMS running when trying without wild card mapping?
2. How does this CMS system interact with IIS; IASPI dll ? or HTTP Handlers/modules?