htaccess仅在域匹配时重定向 [英] htaccess redirect only if domain matches

查看:71
本文介绍了htaccess仅在域匹配时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我需要在域名到达php之前对其进行重定向.当它达到执行标头的能力时,已经为时已晚.

I have a problem where I need to redirect my domain before it hits php. By the time it hits the ability to execute a header, it is too late.

我该怎么办

if (domain == 'www.example.com')
redirect www.domain.com;

在我的.htaccess中?

in my .htaccess?

推荐答案

使用mod_rewrite

Using mod_rewrite

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]

这篇关于htaccess仅在域匹配时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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