php 重定向 无效,php - 从www重定向到非www无效 - 堆栈内存溢出

我有一个在Craft CMS上运行的网站,不确定该问题是否直接与CMS或服务器有关。

我正在使用.htaccess将任何www网址重写为非www版本

# (1)

RewriteEngine On

# (2)

Options +FollowSymlinks

# (3)

#Options +SymLinksIfOwnerMatch

# (4)

#RewriteBase /

# (5)

#RewriteOptions

# (6)

RewriteCond %{HTTPS} =on

RewriteRule ^ - [env=proto:https]

RewriteCond %{HTTPS} !=on

RewriteRule ^ - [env=proto:http]

# Send would-be 404 requests to Craft

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]

RewriteRule (.+) index.php?p=$1 [QSA,L]

RewriteEngine On

# RewriteCond %{HTTPS} !=on

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]

RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]

当我键入domain.com/about它工作正常,但是当我键入www.domain.com/about它将URL更改为domain.com/index.php?p=about

在Craft配置中'omitScriptNameInUrls' => true,启用了'omitScriptNameInUrls' => true, ,将其与以下内容一起从网址中删除index.php。

RewriteEngine On

# Send would-be 404 requests to Craft

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]

RewriteRule (.+) index.php?p=$1 [QSA,L]

这是vhost文件。

ServerName domain.com

ServerAdmin webmaster@domain.com

DocumentRoot /var/www/

Options Indexes FollowSymLinks MultiViews

AllowOverride All

Order allow,deny

allow from all

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

我正在使用Ubuntu 16.04.1,Apache 2.4.18和7.0.8-0ubuntu0.16.04.3托管在Ubuntu上。

有什么我可以测试的方法,以查看是否可以将www重定向到正常工作的非www?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值