laravel internal 500 error - .htaccess

I uploaded my website to a server that is using windows server 2008 r2 and Im getting a problem ( I think its caused because of the .htaccess files ) I get internal 500 error message, im using xampp
My website its not directly on htdocs folder, its on htdocs/server/ maybe that can be an issue?
Also heres my .htaccess file
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Thanks

I don't think Windows Server will obey your .htaccess.
Try define the same logic in your webconfig file.
First of all, you need to direct it to have as your website root, the public folder.
And then inside this folder, try this web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Best wishes

Related

Convert Apache .htaccess rules to IIS web.config to append .php file extensions

I am using below .htaccess code. But I need to convert my .htaccess file content to web.config file. I have no idea how to do it. please check my .htaccess code below:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
How can I convert this to web.config?
we can put below content to the web.config file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/{R:1}.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<compilation tempDirectory="D:\WWW\ovintours.com\tmp" />
</system.web>
</configuration>

Url rewrite Azure PHP?

I have created some PHP app on Azure but this is my first time i am using IIS for my PHP application. I know how to use .htaccess for url rewrite on Apache and there is no problem. But how to accomplish that on Azure IIS. Here is my .htaccess for Apache.
.htaccess
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
You need to use your Web.config file and use the <system.webServer> and <rewrite> rules within this.
You will need to use the following inside your web.config to replicate the code you have above from your .htaccess:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<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>
</system.webServer>
</configuration>
Proper web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="Default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="ModX IIS7 Rule 1 (By Simon Fraser)" stopProcessing="true">
<match url=".*" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_USER_AGENT}" pattern="^.*internal\ dummy\ connection.*$" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="ModX IIS7 Rule 2 (By Simon Fraser)" stopProcessing="true">
<match url="^(manager|assets)" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="ModX IIS7 Rule 3 (By Simon Fraser)" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

How to convert htaccess rules to web.config for IIS7/Symfony?

I have a symfony2 project developed on a linux server and have migrated it (unfortunately!) to a windows server for reasons outside of my control. This all works as it should except for the url rewriting. I tried using the IIS URL Rewrite Module but it failed when converting most of the rules (and stupidly i didn't save a list of which ones it failed on).
It mostly works fine but the app.php is still present at the start of all urls which it shouldn't be. So the urls are domain.com/app.php/correct/path when they should be domain.com/correct/path
Unfortunately i rarely use windows servers and am not good at the web.config syntax so if anyone could suggest what is missing to remove the app.php from the start of all urls on the windows server then that would be greatly appreciated!
The original .htaccess file is:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
The converted web.config file is currently:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url=".?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks very much!
Dave
Have just had this same issue while setting up symfony2 on a Windows server using IIS7.5.
The trick is to go into you web site management section. Look for 'url rewrite', look for 'Import Rules'(somewhere on the right). Then on the new dialogue browse for your .htaccess file in 'SymfonyProject/web/' by default. IIS will throw an error for the trailing slash rule so delete that (Everything seems to work fine without it) and press apply. Viola no app.php.
Be sure to add app.php to your list of default pages also.
I did the above using the standard htaccess file shipped with Symfony2.
EDIT As Requested Below
In the Import Dialog I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / <-This line needs deleting as IIS states "This directive was not converted because it is not supported by IIS: RewriteBase "
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
So the begining of my web.config looks like this:
<defaultDocument enabled="true">
<files>
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Also I have set my web directory as my root directory.
Hope this helps.
Doug.
I know this is an old question but today i had the same problem and i searched everywhere and took me a lot of time to fix it by replace the .htaccess file in web directory to web.config file with this content hope this will help some one .
<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="app.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Symfony Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="app.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I had same issue on a Plesk Linux to Plesk Windows migration. I removed the htaccess file and edited the default web.config file according to previous comments.
In my case, I just needed to change the "app.php" with "index.php" and then it works. This is the content of my web.config file
Hope it will helps !
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Symfony Rewrite" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<tracing>
<traceFailedRequests>
<clear />
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>

IIS URL Rewrite equivalent for Question2Answer mod_rewrite

What IIS URL Rewrite rule set in web.config is equivalent to this mod_rewrite rule set provided in Question2Answer's default .htaccess?
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
The rule differs from a typical WordPress-style rewrite in that nested path elements need to be passed through. Following is an example of a test URL that Question2Answer uses to verify rewriting is working, when Question2Answer is deployed into a qa directory on the server (deployment to the web root fails similarly):
http://localhost:32568/qa/url/test/%24%26-_~%23%25%5C%40%5E%2A%28%29%3D%21%28%29%5D%5B%60%27%3B%3A%7C%22.%7B%7D%2C%3C%3E%3F%23+%CF%80%C2%A7%C2%BD%D0%96%D7%A9?dummy=&param=%24%26-_%7E%23%25%5C%40%5E%2A%28%29%3D%21%28%29%5D%5B%60%27%3B%3A%7C%22.%7B%7D%2C%3C%3E%3F%23+%CF%80%C2%A7%C2%BD%D0%96%D7%A9
This is what IIS Manager's "Import mod_rewrite rules" feature came up with:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" url="index.php?qa-rewrite={R:0}&{QUERY_STRING}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I also added this so that the test URLs would fail in the same way as the actual navigation URLs:
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
There is no answer to a question covering this on question2answer QA's site. Hopefully someone experienced in IIS URL Rewrite here will know.
This configuration works:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="DeduplicateSlashes" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
</rule>
<rule name="CleanRouting" stopProcessing="true">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?qa-rewrite={R:0}&{QUERY_STRING}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<!-- Double escaping is needed for URLs with '+', e.g. for the account page for a username with a space. -->
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</configuration>

Redirect is not working properly in iis

I have a problem similer to this post
I have tried this
RewriteCond %{HTTP_HOST} ^myApplication.com
RewriteCond %{REQUEST_URI} !myApplication/
RewriteRule ^(.*)$ myApplication/$1 [L]
RewriteCond %{HTTP_HOST} www.myApplication.com
RewriteCond %{REQUEST_URI} !myApplication/
RewriteRule ^(.*)$ myApplication/$1 [L]
but the problem is url is working only with www.myApplication.com/myApplication but I want to hide myApplication subfolder .
I will really appreciate any help on this.
UPDATE:
I have tried this which is giving 500 server error.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="mod_rewrite" path="*" verb="*" modules="IsapiModule" scriptProcessor="path to scriptproc" resourceType="Unspecified" requireAccess="None" preCondition="bitness32" />
</handlers>
<rule name="Rewrite to myApplicaton" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)myApplication\.com$" />
<add input="{REQUEST_URI}" pattern="^myApplication/" negate="true" />
</conditions>
<action type="Rewrite" url="/myApplication/{R:0}" />
</rule>
</system.webServer>
</configuration>
The following should do what you want:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to myApplicaton" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)myApplication\.com$" />
<add input="{REQUEST_URI}" pattern="^myApplication/" negate="true" />
</conditions>
<action type="Rewrite" url="/myApplication/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Resources