I’m uploading slim framework project to iis server to be the backend of my angular project but when I enter to the website it produces page not found error in HTML format
my web config is like this
<system.webServer>
<rewrite>
<rules>
<rule name="slim" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
<add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, role, Access-Control-Request-Method, Access-Control-Request-Headers" />
</customHeaders>
</httpProtocol>
</system.webServer>
please could any one help me with this?
odan
October 29, 2019, 10:12pm
#2
Running a Slim 4 app in a sub-directory requires a base path. In your case it’s /test.
$app->setBasePath(’/test’);
Thank you for your response.
where I should put this instruction ? in the public/index.php file or where?
odan
October 30, 2019, 8:19pm
#4
Directly after creating the $app instance.
$app = AppFactory::create();
// here...
http://www.slimframework.com/docs/v4/
I’m using version 3 from slim framework
I tried to put this line of code after the creation of the app like this
$app = new \Slim\App($settings);
$app->setBasePath(’/test’);
but it can not find the index file anymore and gives me this page
odan
November 4, 2019, 8:46am
#6
The setBasePath
method exists only since Slim 4.
So there is not any solution for my problem here ?
odan
November 4, 2019, 4:23pm
#8
There is a solution, but I have not tested it with Slim 3. You can try this anyway:
IIS does not natively support .htaccess files. While there are add-ons that can add this support, you can also import htaccess rules into IIS to use the native rewrites. To do this, follow these steps:
Use Microsoft’s Web Platform Installer to install the URL Rewrite Module 2.0 or download it directly (32-bit / 64-bit ).
Create a new file called web.config
in your Slim root folder.
Using Notepad++ or any XML-safe editor, copy the following code into your new web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*"
stopProcessing="true">
<match url="^public/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(font|img|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="public/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Once the web.config file is created with the correct IIS-friendly rewrite rules, Slim’s links, CSS, JavaScript, and rerouting should work correctly.
If you run Slim 3 is a sub-directory you may also have to fix the basePath:
$container['environment'] = function () {
$scriptName = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);
return new \Slim\Http\Environment($_SERVER);
};
This setup assumes that you store your front-controller file (index.php) under: {project-root}/public/index.php