簡體   English   中英

在yii中使用.htaccess將非www重定向到www

[英]redirect non www to www with .htaccess in yii

這是我的.htacess:

Options +FollowSymLinks 
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

我想將非www請求重定向到www.example.com,但是當我添加時

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

我的css和js及其他文件現在收到404錯誤,所有文件請求都發送到yii控制器

框架:yii2

Php 5.4

阿帕奇:2.4.7

我找到這個答案:

RewriteEngine on

#non-www to www
RewriteCond %{HTTP_HOST} ^adnasor\.ir 
RewriteRule (.*) http://www.adnasor.ir/$1 [R=301,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM