0

I am using an app template based on the advanced template (frontend, common, backend). In the common's main.php (common/config/main.php) I have set a rule to map a particular url (ssid/) to site/index?ssid=. Here is the rule:

'urlManager' => [
     'enablePrettyUrl' => true,
      'showScriptName' => false,
      'rules' => [
          'ssid/<ssid:[\w\-]+>' => 'site/index',
          '<ssid:[\w\-]+>/<path:(.*)\.(jpg|jpeg|png|gif)>'=>'/<path>',
       ]
  ]

The problem I am trying to address with the second rule is that links to media files, such as

<img src="sources/logos/logo.png" />

end up as ssid/sources/logos/logo.png.

However I am skinning this cat, it always prefixes the ssid before the path.

Help? Please? o_o

axtho
  • 15
  • 6
  • 1
    That's how relative URLs _work_ - they get completed to an absolute one, by combining them with the base URL of the current page. Just refer to them with a leading slash, then they will always be relative to the domain root. – CBroe Mar 09 '23 at 08:57
  • You are absolutely pointing in the right direction. Thanks. When I add a tag with the correct substructure the issue goes away. I saw now that Yii adds that "base" path to assets published by it, automatically. – axtho Mar 09 '23 at 10:23
  • UrlManager is not a mod_rewrite. It's not supposed to be used for static asset files. Those should be served directly by http server. You can use `AssetManager` if you need to publish asset files from folders that cannot be reached directly. – Michal Hynčica Mar 09 '23 at 12:19
  • The problem is that the first rule is matching the URL before the second rule has a chance to apply. One way to solve this is to reverse the order of the rules. – Raihan Uddin Mar 14 '23 at 04:08

0 Answers0