www.site.com/myapp vs www.site.com/myapp/ and paths

Topics: Customizing Orchard, Installing Orchard, Troubleshooting
Jan 8, 2012 at 11:17 PM

Here is a funny one.  Locally with orchard 1.3.10 and dev studio's build in server, with localhost:port/myapp it will auto add the ending slash to the home URL making it localhost:port/myapp/  This appears to be important to orchard and allows many relative paths to work correctly, whether it is a navigation, images, media etc.

Unfortunately I deploy it to my standard Windows 2008 R2 server with pretty much default settings and the ending "/" isn't added.  As mentioned, I run into all sorts of issues as a result.  Is this something within orchard, something on the server I should have setup?

I'm working around it by handling both conditions but it's not proper and I'm sure there is a way to better handle this, either within orchard or with some sort of url rewrite module or something.

 

Any ideas are greatly appreciated.

Coordinator
Jan 9, 2012 at 2:27 AM

What kind of issue?

Jan 9, 2012 at 3:32 AM
bertrandleroy wrote:

What kind of issue?

For starters, certain images, paths to theme images etc appear to get messed up with one URL and not the other.  It appears that URL.Content("~") gives different results based on one vs the other.  In addition, I have some rules in a custom navigation that look at the URL and make some decisions.  Finally SEO tends to want to have a single URL source for the same content so http://site/app vs http://site/APP vs http://site/app/ I believe would result in "identical content issues" bumping me down in the list.

Any ideas on how to ensure that the base app level (whether that is site.com/app or site.com or site.com/sub/app would always append the trailing / in the most elegant fashion?  Also any ideas on why it does it locally and not on the server?

Thanks for the reply and assistance.

Jan 9, 2012 at 4:21 AM

There is an URL Rewrite IIS plug-in that can handle this for you, along with a few other common SEO and rewrite scenarios. It will redirect url's without the trailing slash to one with it, and it can also redirect all mixed or upper case URL's to the all lower case version (since search engines are case sensitive). Google search "url rewrite iis asp.net mvc" or something similar to find it.

It sounds like at least part of your issues are from your own code that's using Url.Content(); are you sure the issue isn't that you didn't put in checks for presence of a slash before building/appending to URL's? I have so far not encountered any issues like the one you mention because all the paths to images scripts and stylesheets in my modules and resources are done using the absolute path ( "~/modules/mymodule/scripts/site.css", or "~/themes/mytheme/content/images/file.jpg"). 

Jan 9, 2012 at 4:30 AM
Humm it's very likely I'm doing my URL comparison incorrectly. What is the best way for me to review the current url? specifically I'm looking for "section" of the site based upon the naming of the page. Under consideration is that fact that lists and blogs have site.com/myapp/section/item while others are more easily defined as site.com/myapp/section or site.com/myapp/section_page2.

Thanks for your thoughts. I'll take a look at the URL rewrite item you look for and perhaps you'll have some great advice on better coding for the condition and situation above.

On Sun, Jan 8, 2012 at 10:21 PM, TheMonarch <notifications@codeplex.com> wrote:

From: TheMonarch

There is an URL Rewrite IIS plug-in that can handle this for you, along with a few other common SEO and rewrite scenarios. It will redirect url's without the trailing slash to one with it, and it can also redirect all mixed or upper case URL's to the all lower case version (since search engines are case sensitive). Google search "url rewrite iis asp.net mvc" or something similar to find it.

It sounds like at least part of your issues are from your own code that's using Url.Content(); are you sure the issue isn't that you didn't put in checks for presence of a slash before building/appending to URL's? I have so far not encountered any issues like the one you mention because all the paths to images scripts and stylesheets in my modules and resources are done using the absolute path ( "~/modules/mymodule/scripts/site.css", or "~/themes/mytheme/content/images/file.jpg").

Read the full discussion online.

To add a post to this discussion, reply to this email (orchard@discussions.codeplex.com)

To start a new discussion for this project, email orchard@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
================
John B Fraser
================

Jan 9, 2012 at 4:50 AM

Not sure I understand. Are you trying to determine where the user currently is on the site by examining the current URL? For example, if URL starts with www.site.com/myapp/some-section-name/, then you know the user is on the "some-section-name" part of the site? 

If so, then you can probably get this through the action name, or the Route Values. From the view you can do Url.RequestContext.RouteData.Values["key"] to get the route value. In your route definitions you either already have parameters there that have the information you want (which would already be in the RouteData.Values collection), or you can add defaults or tokens to the Route definitions so the parts of the URL you want to get information from will be available in RouteData.Values.