目前,uni只为我们提供了一个iis服务器来托管我们的php网站,我们想使用laravel框架,它确实在主页上工作。但不在任何其他控制器上。
我的公用文件夹中当前的web.config是,

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)/$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
        </rule>
        <rule name="Imported 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>

我的路线是
Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

我不太了解iis,所以你有什么想法来配置它使之工作吗?
附笔。
我们没有在camps中配置iis服务器的权限,我们有权做的是上载web.config
提前谢谢。

最佳答案

最后我解决了这个问题,这不是一个完美的方法,但它确实有效。

<rule name="rewrite all requests to index.php" stopProcessing="true">
     <match url="^(.*)$" ignoreCase="false" />
     <conditions logicalGrouping="MatchAll">
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
     </conditions>
     <action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>

<rule name="Redirect / to index.php" stopProcessing="true">
     <match url="^" ignoreCase="false" />
     <action type="Rewrite" redirectType="Permanent" url="index.php" />
</rule>

正如我在开头提到的,这不是一个完美的解决方案,它将所有的url重写为index.php,因此url并不漂亮,比如,
a.com/login -> cc>
a.com/index.php/login -> cc>
a.com/>404
因为我不太熟悉iis配置/重写,所以必须有更好的解决方案,所以改进这行配置文件的建议将是非常好的。
无论如何,它在您没有权限设置IIS服务器的情况下工作。
它应该使laravel项目在任何iis服务器上运行,而不更改服务器的设置。
参考文献
IIS rewrite and asp.net route
redirect all to one page

10-06 12:41
查看更多