Reputation: 14229
People, I am in developing an asp.net website with a Multilanguage content and SEO is a very high priority.
I have managed to get my website to display different URLs through asp.net URL routing to display site.com/ar and site.com/en depending on the selected language and this works fine on .apsx page on the root directory. However, this does not work in pages in subdirectories for example site.com/en/Account/Login.aspx and I have spent days trying to make my URL routing to work with my subdirectories but I was not able to get it to work with subdirectories.
So, from the-easy-way point of view is it better to have different physical directories /ar and /en on my root directory with different content pages for each language. This is also preferred since the layout for /ar page are completely flipped horizontally because ar = Arabic = right to left language.
Please do share your opinions on the advantages disadvantages of this approach.
Upvotes: 1
Views: 1729
Reputation: 1878
Personally, I would avoid physical directories and go for the routing approach. It will be much easier to add languages in the future, plus if you find you need to support cultures (en-US, en-CA, en-GB etc.) you can easily introduce default cultures (ie. if there's no en-GB resource, default to en-US) rather than create a second physical copy of the assets. I've worked on large websites that had duplicate files under localised directories. It starts to hurt quickly as you add languages.
As for the problem with routes and sub-directories, you could try putting a constant in the route, as that makes it easier for a url to match the pattern. I'm using 'X' here:
routes.Add("LocalisedRoute", new Route
(
"{lang}/X/{path}"
, new IRouteHandler()
));
Now both of these paths should match:
That may not be necessary if you take the approach outlined in @TonyStark 's link, but in general I've found adding a constant to be useful when fiddling with routes in the past.
EDIT: Note that Google's recommendation is to use a sub-domain for each language, eg. en-US.site.com.
Upvotes: 0
Reputation: 33
I thought webforms using routes was pretty straight forward using the following:
routes.MapPageRoute("", "Category/{action}/{categoryName}", "~/categoriespage.aspx")
Also found this article which might be of some use depending on how your utilizing Culture Info, or not. http://www.codeproject.com/Articles/72478/Web-Site-Globalization-With-ASP-NET-Routing
Upvotes: 0
Reputation: 48250
The URL based approach should work correctly even on subdirectories. Because you mention "subdirectories" rather than "controllers/actions" I assume you have your application implemented with ASP.NET WebForms rather than the MVC.
If this is so, you url rewrite your requests in your Application_BeginRequest
:
public void Application_BeginRequest( object sender, EventArgs e )
{
HttpApplication app = (HttpApplication)sender;
HttpContext ctx = app.Context;
string PathAndQuery = ctx.Request.Url.PathAndQuery;
// parse the PathAndQuery and if it is of the form
// en/Subdir1/Subdir2/resource.aspx
// split it into [en] (virtual part) and [Subdir1/Subdir2/resource.aspx] (physical part)
string VirtualPart = GetVirtualPart( PathAndQuery );
string PhysicalPart = GetPhysicalPart( PathAndQuery );
ctx.RewritePath( PhysicalPart );
}
With such approach, you have your physical structure in the filesystem and requests of the form en\Subdir1\Subdir2\resource.aspx
are correctly routed to Subdir1\Subdir2\resource.aspx
.
Although the example shows manual rewriting, you can use any existing rewriting technology if it fits your needs.
This is just to get you started. However, if you have any specific issues in your implementation of the url rewriting, I assume you'd have to ask other specific questions so that people can help you out with specific problems. If you just say I've spent days and it does not work then it is impossible to help you with your specific approach.
Upvotes: 1