【问题标题】:Laravel get all traffic over www. domainLaravel 通过 www 获得所有流量。领域
【发布时间】:2015-07-28 05:50:54
【问题描述】:

我希望通过www.domain.com 而不是domain.com 获得所有流量。

如何在 Laravel 4 中做到这一点?但问题是,我想使用.htaccess,因为在 Laravel 我有这个:

.htaccess文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

</IfModule>

但问题是,当我转到 domain.com/login 时,它会重定向到 www.domain.com/index.php,我不希望这样。

如何解决重定向到 www.domain.com/login 的问题?

【问题讨论】:

  • 您需要将重定向到www. 的最后一个块移到重定向尾部斜杠的规则上方。
  • 我怎么会这么笨...谢谢老兄!这对我有帮助! :)

标签: php .htaccess mod-rewrite laravel redirect


【解决方案1】:

感谢@MikeRockett,我找到了解决方案!

解决方案代码:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    #redirect from naked url
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 2013-01-06
    • 2018-02-27
    相关资源
    最近更新 更多