【问题标题】:Laravel 5.2 : only route '/' works in windows iis serverLaravel 5.2:只有路由'/'在 windows iis 服务器中有效
【发布时间】:2016-11-15 22:16:19
【问题描述】:

今天我尝试在 windows iis 服务器中访问我的项目路由时遇到问题。

我的申请网址是:demo.example.com/testing/

根路由正在工作'/',但不能与另一个一起工作。

例如,如果我尝试使用 '/home/' 路由单击菜单,则 url 将类似于 demo.example.com/home''testing' 不知何故消失了。

PS : 我已经删除了'public' 文件夹,将公用文件夹中的所有文件移到外部,并将其他文件移到新文件夹中。

路线示例:

Route::get('/', 'frontend\frontController@index');

Route::get('/login', 'frontend\frontController@login');

感谢您的帮助!

【问题讨论】:

标签: php laravel routes


【解决方案1】:

我通过下载 URL Rewrite 2.1 并在 web.config 中解决了这个错误。

O meu ficheiro web.config

    <!--
    Rewrites requires Microsoft URL Rewrite Module for IIS
    Download: https://www.iis.net/downloads/microsoft/url-rewrite
    Debug Help: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
-->
<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>

【讨论】:

    【解决方案2】:

    归结为 URL 重写。我遇到了完全相同的问题,我需要在 web.config 中添加一条规则:

    <rule name="routes" 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="public/index.php/{R:1}" />
    
                    </rule>
    

    来自这篇博文: https://laracasts.com/discuss/channels/servers/iis-8-laravel-webconfig

    【讨论】:

      【解决方案3】:

      可以通过demo.example.com/testing/public/index.php访问登录页面吗?/login

      如果是,问题可能出在您的服务器配置或 .htaccess 中

      我刚刚遇到了同样的问题,为我启用 mod_rewrite for apache2 修复它。

      您可能应该阅读:

      https://laravel.com/docs/5.0/configuration#pretty-urls

      Can't route properly in Laravel

      Can't access URL in Laravel routes

      最后一件事,你不应该在下面做这件事。

      PS:我已经删除了“公共”文件夹,将公共文件夹中的所有文件移到外部,并将其他文件移动到新文件夹中。

      不要再搞乱文件夹结构了。不要做你不知道的事情!

      【讨论】:

        【解决方案4】:

        您不应该将 laravel 放在子文件夹中。 您的子域应该直接指向应用程序,而不需要任何其他子文件夹,因为 Laravel 将使用绝对路径导航到您的路由。例如

        Route::get('home', ...)
        

        将始终导航到 yourdomain.com/home,即使它实际上与 yourdomain.com/laravel/home 匹配,除非您对设置进行大量更改。

        【讨论】:

          猜你喜欢
          • 2018-02-07
          • 2015-10-04
          • 1970-01-01
          • 2018-01-01
          • 2015-08-17
          • 2023-03-04
          • 1970-01-01
          • 1970-01-01
          • 2019-01-10
          相关资源
          最近更新 更多