Update URI processing of web servers

This commit is contained in:
Pig Fang 2018-08-16 18:01:16 +08:00
parent 40deffb3b9
commit daaedeed7e
2 changed files with 69 additions and 40 deletions

View File

@ -1,10 +1,26 @@
RewriteEngine On <IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase / RewriteEngine On
RewriteRule (^\.|/\.) - [F] # You may need to uncomment the following line for some hosting environments,
# if you have installed to a subdirectory, enter the name here also.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f # Black list protected files
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (^\.|/\.) - [F]
RewriteRule ^storage/.* - [F]
RewriteRule ^.*$ index.php [L] # Redirect trailing slashes if not a folder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle front controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

View File

@ -1,34 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?> <configuration>
<configuration> <system.webServer>
<system.webServer> <defaultDocument>
<staticContent> <files>
<mimeMap fileExtension="." mimeType="image/png" /> <clear />
<remove fileExtension=".woff"/> <add value="index.php" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" /> <add value="index.html" />
<remove fileExtension=".woff2"/> </files>
<mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" /> </defaultDocument>
</staticContent> <!-- Fix webfont issue on IIS -->
<!-- For rewrite to work install URL Rewrite Module via Web Platform Installer --> <staticContent>
<rewrite> <mimeMap fileExtension="." mimeType="image/png" />
<rules> <remove fileExtension=".woff"/>
<rule name="bss" patternSyntax="Wildcard"> <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<match url="*" /> <remove fileExtension=".woff2"/>
<conditions> <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </staticContent>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <!-- For rewrite to work please install IIS URL Rewrite Module -->
</conditions> <rewrite>
<action type="Rewrite" url="index.php" /> <rules>
</rule> <rule name="Block access to dotfiles">
</rules> <match url="(^\.|/\.)" ignoreCase="false" />
</rewrite> <action type="CustomResponse" statusCode="403" statusReason="Forbidden" />
</system.webServer> </rule>
<rule name="Block access to storage path">
<!-- Protect .env file --> <match url="^storage/.*" ignoreCase="false" />
<location path="~/.env"> <action type="CustomResponse" statusCode="403" statusReason="Forbidden" />
<system.web> </rule>
<authorization> <rule name="Redirect trailing slashes if not a folder" stopProcessing="true">
<deny users="*"/> <match url="^(.*)/$" ignoreCase="false" />
</authorization> <conditions>
</system.web> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</location> </conditions>
</configuration> <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Handle front controller" 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>