Friendly URL for files

Andrew Yarwood asked on April 15, 2016 11:32

I struggle to keep .png, .jpg and other graphic extensions for uploaded files. Once I leave this field blank I can access the file only without an extension. I.e.: /logo rather than /logo.png. Following Kentico 9 documentation for Friendly URLs for files I found the examples:

;.aspx - extensionsless URLs by default, also allows aspx
.html;.htm;;.asp - html extension by default, also allows htm, extensionless and asp

so I understand if I set up: .png;.jpg for Files friendly URL extension then I should be able to access my assets via .png for instance.

However when I do it and then go to Properties -> General for the uploaded file I can see the link which leads to:

http://domain/assets/logo.png;.jpg

which I believe is incorrect. Can you advice how to set up this field correctly?

Recent Answers


Anton Grekhovodov answered on April 15, 2016 12:45

Hi Andew,

You should read URL format and configuration "Reference - URL settings section"

Image Text

2 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 15, 2016 13:27

Hi Andrew,

This is how I understand. if you keep "Friendly URLS extensions" and "Files Friendly URLS extensions" empty instead of the default values of ".aspx", then you should be able access your home page which /home.aspx as /home and your images like /media/websitename/logo.aspx(PNG) as /media/websitename/logo.png. This means that you will be able to access your resources the way they are.

Screenshot of settings

Let me know if this helps.

Cheers, Chetan

1 votesVote for this answer Mark as a Correct answer

Andrew Yarwood answered on April 15, 2016 15:48

Hello,

Thank you for the answer.

I set this back to .aspx and I am able to view the file as http://website/assets/logo.aspx now however it is still not possible to view it as .png (which is the original extension of this file). I simply get 404 error.

I had this issue with Kentico 6 as well. Is it possible it requires some web.config changes to make it work? It is a fresh installation.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 15, 2016 17:28

Can you try this in your web.config file.

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">

Under your system.webserver settings check if you have this enabled.

P.S:- You need to keep those two settings to blank or if you want to support you could do like this

Friendly URL extension - `.aspx;.html;.htm;;

Files friendly URL extension - Keep it blank, this will ensure no extension being added to your file and they will be accessible as it is`

Let me know if this works.

Cheers Chetan

2 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 15, 2016 20:16

Hi Andrew,

Does that help you resolve your problem?

Cheers Chetan

0 votesVote for this answer Mark as a Correct answer

Andrew Yarwood answered on April 18, 2016 12:08

It is necessary to close the tag. <modules runAllManagedModulesForAllRequests="true" />
It didn't help unfortunately... :(

In IIS log I am getting:

2016-04-18 10:03:54 188.68.249.218 GET /assets/logo.png - 80 - 87.204.150.129 Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/49.0.2623.112+Safari/537.36 http://domain.com/CMSModules/Content/CMSDesk/Properties/General.aspx?mode=edit&tabselemid=m_c_plc_lt_ctl00_HorizontalTabs_l_t_tabsElem&nodeid=3&culture=en-GB 404 0 2 15

but the file exists obviously.

0 votesVote for this answer Mark as a Correct answer

Andrew Yarwood answered on April 18, 2016 12:32 (last edited on April 18, 2016 12:32)

I noticed that when I set the option: Use URLs with trailing slash: to use WITH TRAILING SLASH and having Files friendly URL extension: and Friendly URL extensions: empty then the link: http://domain.com/assets/logo.jpg/ works fine. However if I set it to use without trailing slash then it stops working if I try http://domain.com/assets/logo.jpg (without /) ....

0 votesVote for this answer Mark as a Correct answer

Andrew Yarwood answered on May 6, 2016 11:12

After investigation with the Kentico Support the issue was with runAllManagedModulesForAllRequests="true" incorrectly placed. The answer above was incomplete because it is a rare case when <modules> will exist by itself in the CMS web.config file.

My part of web.config file with this issue resolved is as below:

  <!-- FiftyOne END -->
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
      <remove name="XHtmlModule" />
      <remove name="CMSApplicationModule" />
      <add name="XHtmlModule" type="CMS.OutputFilter.OutputFilterModule, CMS.OutputFilter" />
      <add name="CMSApplicationModule" preCondition="managedHandler" type="CMS.Base.ApplicationModule, CMS.Base" />
    </modules>

In CMS Settings I've got fields: "Friendly URL extensions" and "Friendly files URL extensions" set as blank. Additionally I checked and it works with 'Removed trailing slash' option and 'Redirect all to lower-case'.

Thank you for your help.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.