I want to deploy laravel projects on our IIS 10, running on windows server 2016. What is the easiest and still secure way to do that?
Developers opt to deploy Laravel on shared hosting mainly for cost savings. Shared hosting is cheap and is generally preferred by those unaware of its detriments. Similarly, developers generally install and deploy Laravel to shared hosting without considering the problems it causes for the end-users.
This is how I did it; I'm not sure it is the right way.
In your web.php route file put:
Route::get('/', function () {
return view('welcome');
});
Route::get('/also', function () {
return view('welcome');
});
Add the file web.config in public dir and paste the rules:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You should now be able to access both URLs meaning laravel routing works as intended. If you try another non-existent route you will get a laravel exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With