微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – IIS服务器,如何为Laravel 5配置url重写?

目前,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,所以你有任何想法来配置它以使其工作吗?

附:
我们无权在阵营中配置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 – > a.com/index.PHP/login
> a.com/ – > a.com/index.PHP
> a.com/login/index.PHP – > 404

因为我对IIS配置/重写不是很熟悉,所以必须有一些更好的解决方案,所以改进这行配置文件的建议会很棒.

无论如何,它在您无权设置IIS服务器的情况下工作.

它应该使Laravel项目在任何IIS服务器上运行,而无需更改服务器的设置.

参考文献

> IIS rewrite and asp.net route
> redirect all to one page

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐