Make URLs clear

Aug 5, 2012 at 12:51 AM

I want to make the URLs for my website much clear so people can understand them. Currently the URLs go like this mysite.com/C-Sharp or PHP etc. But since I made a new column called pCategory and every tutorial is given a category e.g. C# can I make a new folder copy the default.cshtml and then make it only request C-Sharp pages and same for the rest so if it is PHP page make a PHP folder and put default.cshtml and make it request PHP pages only?

However for pages like Credits, Contact they should use the standard URL like mysite.com/contact

 

How can I do this?

 

Thanks

Aug 5, 2012 at 5:20 PM
Edited Aug 5, 2012 at 5:21 PM

It is not a good idea to copy default page / create folders , etc. - it probably will work but you will create additional copies of code that are not needed. After some time it will be hard for you to modify the site , because you will end up with so many places where you have code...in addition to that you should not change existing tables (the best way would be to create new table for your needs and create relation between columns/tables)

Maybe you could use routing , open _AppStart.cshtml and add new routes , something like:

RouteTable.Routes.MapWebPageRoute("categoryHere/{rcPageName}/{rc0}/{rc1}", "~/Default.cshtml", new { rcPageName = "default", rc0=-1,rc1=-1});

 this should allow you to access pages thru url like this domain.com/categoryHERE/pageNameHere

 

or the way i do it (this will be included in next version of razorC):

in default.cshtml add this after Page.mDescription=data.mDescription;

 if (data.pBodyFile.StartsWith("_addon_") && !Context.GetRouteValue("rc0").IsEmpty() ){
        //load tags based on urldata[0] 
    var selectQueryString1 = "SELECT mTitle, mDescription, mKeywords FROM rc_Pages WHERE pName = @0";
    
    var data1 = db.QuerySingle (selectQueryString1, Context.GetRouteValue("rc0"));
    if (data1!=null){
    Page.mTitle = data1.mTitle;
    Page.mKeywords = data1.mKeywords;
    Page.mDescription = data1.mDescription;
    }
    }

 



What it does it check if requested page uses pBodyFile that starts with _addon_  and if there is rc0 parammeter after page name (it will try to load new meta tags based on that rc0 parammeter), so

you can create regular pages category1, category2, category3 etc. set pBodyFile to your addon (will explain the addon at the end) and you will be able to acess pages like domain/category1/some-page or domain/category1/some-page2 or domain/category2/page3

the addon should go to rcaddons>addonName>Body>_addon_addonName_Category.cshtml and it should request content (pTitle, pText) based on rc0  

so where pName = Context.GetRouteValue("rc0")

 

Aug 8, 2012 at 7:11 PM
razorc wrote:

It is not a good idea to copy default page / create folders , etc. - it probably will work but you will create additional copies of code that are not needed. After some time it will be hard for you to modify the site , because you will end up with so many places where you have code...in addition to that you should not change existing tables (the best way would be to create new table for your needs and create relation between columns/tables)

Yes it can be a problem copy and pasting but I HARDLY edit the default.cshtml file, and you are right about copying code I don't need maybe I can make a helper for that? However I think this would be the best way for me to do this..

 

How can I got about it? If I do it this way it will also be easy for me in the admin area too. 

Aug 11, 2012 at 5:10 PM

As i said before it is not the way i would go HOWEVER you now what you need and if the "extra folder" solution will work for you...go for it

ex. PHP

in _AppStart add this before the rule that is now in this file

RouteTable.Routes.MapWebPageRoute("php/{rcPageName}/{rc0}/{rc1}", "~/php/Default.cshtml", new { rcPageName = "default", rc0=-1,rc1=-1});

create folder php and copy default.cshtml file there. Edit default.cshtml and change this (line 9 i belive) 

+ "WHERE pName = @0";

to something like that 

"WHERE pName = @0 and YOUR_CATEGORY_COLUMN='php'";
Aug 12, 2012 at 12:48 PM
Edited Aug 13, 2012 at 12:08 AM

I'll go with your first idea, however will it be good for SEO? and the problem is since I already got URLs like mysite.com/PHP will I need to re-index them all? Because I use Google products and in Google Analytics it will duplicate urls like mysite.com/PHP/PHP and mysite.com/PHP this will be pretty annoying. Users can still get to /mysite.com/PHP! 

 

Also one more thing, users can access urls like this Mysite.com/php and MySite.com/PHP does this letter casing matter? It won't cause SEO problems will it..?

 

Edit > I just realized that users can go to other pages like Mysite.com/PHP/HTM Ltutorial (this will be very bad for SEO and it will duplicate URLs in Google WebMaster tools, Analytics and Search)

 

EDIT AGAIN> I posted it on here http://forums.asp.net/p/1833256/5104883.aspx/1?p=True&t=634803952445222323 you can answer there since asp.net has a bigger user base.