Yii2 PrettyUrl and ScriptName

143 Views Asked by At

here is what i did

in web.php

'request' => [
      
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
         ]
 ],


 'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => false,
        'showScriptName' => false,
        'rules' => [
        ],
    ],

.htaccess

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

in browser, if the link

http://localhost:8888/site/web/

it will show data in site index but if I dive inside pages, it will show nothing, if i added index.php the pages work and shows the data , but there is another problem in some pages I have uploaded images and save there path in db like this:

   upload//63b521df1b0e0.jpg  

it shows nothing because the link become like this :

http://localhost:8888/site/web/index.php/listing/upload//63b521df27bf0.jpg

and it should be :

http://localhost:8888/site/web/upload//63b521df27bf0.jpg 

so what i missed ?

1

There are 1 best solutions below

0
Sasha Javorski On

if you need http://localhost:8888/site/web/upload//63b521df27bf0.jpg you must contruct url as follows:

'https://'.$_SERVER['HTTP_HOST'].'/site/web/'.$model->image_path;

in your version you use the relative path, but I suggest to use absolute path.