I have a simple Laravel 5 app. It was developed on Xampp, and worked perfectly. I copied it onto the production server, and it does not work. Something is wrong with the web.config file, because if I remove it, then the app works perfectly with index.php/path
My webconfig is as follows:
<?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>
The app is located at a subfolder of the website and I cannot create a new site, but I can restart IIS as needed. I really don't know IIS very well (in fact I hate it), so I don't know where to check, but since the app works without the web.config, I assume it must be the culprit.
IIS Needs to have the URL Rewrite Module for the Laravel web.config to work.
On XAMPP, it will work out of the box as the Apache mod_rewrite module is included and most of the configuration settings are already provided by XAMPP.
Microsoft URL Rewrite.
Download it from here
Related
In my Laravel + Vuejs project I have the following structure:
wwwroot/dist folder where the client application is located in /wwwroot/dist.
wwwroot/public folder, entry point of Laravel
The client application consumes a Laravel REST API. There are also other APIs for different utilities.
I have the following web.config file in /wwwroot. The idea is that all requests go to /dist to access the client app, except those coming from the api|src|flyer|admon|user subdomains. This is my web.config:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="/public/index.php" />
<add value="/dist/index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script">
</handlers>
<rewrite>
<rules>
<rule name="specific routes" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*(api|src|flyer|admon|user)\.mysite\.com.*" />
</conditions>
<action type="Rewrite" url="/public/index.php" appendQueryString="True" />
</rule>
<rule name="general routes" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="/dist/" appendQueryString="True"/>
</rule>
</rules>
</rewrite>
</system.webServer>
All requests that work with the first rule (api|src|flyer|admon|user subdomains) work correctly. The issue is that my client app doesn't work, it seems like it doesn't process Javascript files. Note that in the content of the JS files it shows that of index.html:
The problem is not in my Vuejs application, because I have it installed on another Apache/Linux machine and everything works correctly with the same deployment structure.
EDIT
This is my virtual path config in Azure, where my web.config is placed:
There's a way to point all my subdomains to the same name folder, using Windows Server | IIS - Rewrite Rule or Proxy?
Example:
subdomain1.domain.com ----> C:\customers\development\subdomain1
subdomain2.domain.com ----> C:\customers\development\subdomain2
subdomain3.domain.com ----> C:\customers\development\subdomain3
Is it possible do automatically?
I've tryied these web.config rules
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks in advance!
URL rewrite is mainly used to rewrite URL not physical path. So you have to create a web app with root folder C:\customers\development and bind all subdomains to this IIS site. Then modify your rule to
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/{REQUEST_URI}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Please modify ^(?!www\.)(.*)\example\.com$ to ^(?!www\.)(.*)\.example\.com$.
Finally, you should be point subdomain to subfolder
Besides, if the application in folder domain1/domain2 and domain3 are three independent projects then you need to use sub-application instead of a folder.
Having the SSL certificate supposedly implemented on the server, what's the next step to have "https//" at the beginning of the URLs?
Thanks for the overwhelming help. I managed to resolve my problem and was actually very simple. I had to create a web.config file and copy paste the next code
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.example.es/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
And after that, replace the url with the one from your own web. Simple but if you donĀ“t have any knoledge on the matter is actually very frustrating
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?
This is how I did it; I'm not sure it is the right way.
Install URL Rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite)
Put repo in some folder E:/sites/helloworld
In IIS add a virtual directory called "helloworld" pointing to E:/sites/helloworld/public
Make sure folders bootstrap/cache and storage is open for writing.
Dont forget to make env file.
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.
so I uploaded my website in GoDaddy and I used a Windows Hosting (Plesk). My only problem is that since it isn't running Apache as far as I know, it won't read my .htaccess file, which has all of my mod_rewrite code to remove the index.php in the URL. So my question is how do I implement a mod_rewrite in Plesk?
You can rewrite .htaccess file to IIS's web.config and place it inside /httpdocs folder.
You can do it by guides like this or this online converter or if you have Windows Server you can convert .htaccess by this guide (or you can share your .htaccess and i'll try to convert it for you)
I've found this snippet maybe it can help you:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Index">
<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/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>