Browse Source

增加Apache和IIS支持

tbphp 2 years ago
parent
commit
2179d30439
4 changed files with 50 additions and 3 deletions
  1. 14 0
      .htaccess
  2. 1 1
      api/database.php
  3. 5 2
      api/index.php
  4. 30 0
      web.config

+ 14 - 0
.htaccess

@@ -0,0 +1,14 @@
+<IfModule mod_rewrite.c>
+  Options +FollowSymlinks -Multiviews
+  RewriteEngine On
+
+  RewriteRule ^index\.html$ - [L]
+  RewriteCond %{REQUEST_FILENAME} !api
+  RewriteCond %{REQUEST_FILENAME} !-d
+  RewriteCond %{REQUEST_FILENAME} !-f
+  RewriteRule . /index.html [L]
+
+  RewriteCond %{REQUEST_FILENAME} !-d
+  RewriteCond %{REQUEST_FILENAME} !-f
+  RewriteRule ^/api(.*)$ api/index.php/$1 [QSA,PT,L]
+</IfModule>

+ 1 - 1
api/database.php

@@ -3,5 +3,5 @@ return [
     'host'     => '127.0.0.1',
     'dbname'   => 'svm',
     'user'     => 'root',
-    'password' => 'gQ952429d',
+    'password' => '426351Tb',
 ];

+ 5 - 2
api/index.php

@@ -36,10 +36,13 @@ try {
         // 判断URL里面是否有兼容模式参数
         $_SERVER['PATH_INFO'] = $_GET['s'];
         unset($_GET['s']);
-        $path ?? $path = trim($_SERVER['PATH_INFO'], '/');
-        $paths         = explode('/', $path);
     }
+
     // 解析
+    if (isset($_SERVER['PATH_INFO'])) {
+        $path  = trim($_SERVER['PATH_INFO'], '/');
+        $paths = explode('/', $path);
+    }
     $controller = 'Controller\\' . ucfirst($paths[0] ?? 'index');
     $action     = $paths[1] ?? 'index';
 

+ 30 - 0
web.config

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <system.webServer>
+        <rewrite>
+            <rules>
+                <rule name="已导入的规则 1" stopProcessing="true">
+                    <match url="^index\.html$" ignoreCase="false" />
+                    <action type="None" />
+                </rule>
+                <rule name="已导入的规则 2" stopProcessing="true">
+                    <match url="." ignoreCase="false" />
+                    <conditions logicalGrouping="MatchAll">
+                        <add input="{REQUEST_FILENAME}" pattern="api" ignoreCase="false" negate="true" />
+                        <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.html" />
+                </rule>
+                <rule name="已导入的规则 3" stopProcessing="true">
+                    <match url="^api(.*)$" ignoreCase="false" />
+                    <conditions logicalGrouping="MatchAll">
+                        <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="api/index.php/{R:1}" appendQueryString="true" />
+                </rule>
+            </rules>
+        </rewrite>
+    </system.webServer>
+</configuration>