Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sebastian Dammark 581 posts 1385 karma points
    Oct 16, 2019 @ 08:24
    Sebastian Dammark
    0

    URL rewrite for media only when not on production ?

    I have a website with a rather large media section.

    So to avoid copying media between environments I've added the following to the UmbracoDeploy.Settings.config file

    <?xml version="1.0" encoding="utf-8"?>
    <settings xmlns="urn:umbracodeploy-settings">
        <excludedEntityTypes>
          <add type="media-file" />
        </excludedEntityTypes>
    </settings>
    

    This also means that all requests on DEV and STAGING will fail since the files doesn't exists.

    Wouldn't it be possible to have an URL re-write that handle this ? So when the domain doesn't contain maindomain.tld then use maindomain.tld/path/to/media

    Any suggestions on how this should look ?

  • Erik Eelman 79 posts 319 karma points
    Oct 17, 2019 @ 06:48
    Erik Eelman
    0

    Hi Sebastian,

    You could use something like this:

    <rule name="Media2Live" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^media/(.+)" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="https://www.yourwebsite.com/{R:0}" redirectType="Temporary" />
    </rule>
    

    This redirects the media calls to the live domain.

    Erik

  • Sebastian Dammark 581 posts 1385 karma points
    Oct 21, 2019 @ 17:59
    Sebastian Dammark
    0

    This works flawlessly in combination with config transforms

    https://our.umbraco.com/documentation/Umbraco-Cloud/set-up/Config-Transforms/
    

    But what if you're running a website with multiple domains ? In your example the domain is hardcoded, are there any way around that ?

  • Erik Eelman 79 posts 319 karma points
    Oct 23, 2019 @ 07:29
    Erik Eelman
    0

    I'm not sure i understand your question. Do you mean you have a website with multiple domains and want to redirect the media request to different domains?

    If thats the case you could add a rule for every domain you want to redirect to and add a extra add a condition to the rule. For example:

    <rule name="Media2Live" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="^media/(.+)" />
              <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_HOST}" pattern="www.domaintomatch.com" />
              </conditions>
              <action type="Redirect" url="https://www.livewebsite.com/{R:0}" redirectType="Temporary" />
    </rule>
    
Please Sign in or register to post replies

Write your reply to:

Draft