如何在laravel 4中将非www域重定向到www? [英] how can redirect domain non-www to www in laravel 4?

查看:61
本文介绍了如何在laravel 4中将非www域重定向到www?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试通过.htaccess文件将我的域名从非www重定向到www. 我之前的htaccess代码是

Hello I try to redirect my domain name from non-www to www via .htaccess file. My previous htaccess code was

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

我将其替换为代码

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.forexfunction\.com
RewriteRule (.*) http://www.forexfunction.com/$1 [R=301,L]

但替换此代码后,我遇到404错误. 我该如何解决我的问题? 预先感谢.

but i face 404 errors after replacing this code. How can i solve my problem? Thanks in advance.

推荐答案

这是将非www请求重定向到www请求的代码.

This is the code which will redirect non-www request to www request.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

.htacccess文件的外观如下.

Here is how you .htacccess file will look like.

<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine On

  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

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

</IfModule>

希望有帮助.

这篇关于如何在laravel 4中将非www域重定向到www?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆