0

I am working on a project which is in Yii2. I have to integrate swagger UI for API documentation. My current directory structure:

current directory structure enter image description here

This is what the .htaccess looks like:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
</IfModule>

When I hit http://xxxx-api.local/swagger/index.php it treats it as a legit API and because there is no such controller and action it returns 404.

My question is do we have a way to render index.php from another swagger directory if the user hits this http://xxxx-api.local/swagger/index.php URL in the browser?

I tried to twik the .htaccess but it is not working.

  • _"it treats it as a legit API and because there is no such controller and action it returns 404"_ - it treats it as such, because the request does not match a physically existing file or folder - your `swagger` folder is outside of your `web` folder, which I assume you have the document root pointed to. https://stackoverflow.com/a/38517303/1427878 – CBroe Nov 11 '22 at 13:42
  • @CBroe, so if I move swagger inside the web folder, how should I tweak .htaccess so that it renders Swagger document? – Paresh Maheshwari Nov 11 '22 at 13:56
  • 1
    If you just need to target the existing swagger/index.php file - then that should not require any modifications; the rewriting to the yii2 index.php happens only, when the requested URL does not match an existing file or folder. If swagger itself needs URL rewriting however - then you would need to implement an exception in your yii2 .htaccess, that lets these requests pass through. – CBroe Nov 11 '22 at 14:03

0 Answers0