htaccess的重定向非www到www,除了特定的子目录 [英] .htaccess redirect non-www to www except for a particular subdirectory

查看:116
本文介绍了htaccess的重定向非www到www,除了特定的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向所有example.com到www.example.com除了example.com/subdirectory应该保持原样,没有任何重定向。

I need to redirect all example.com to www.example.com except for example.com/subdirectory which should remain as is without any redirection.

推荐答案

我已经通过在.htaccess文件下面的解决了这个问题。

I have solved the problem by having the following in the .htaccess file

RewriteEngine叙述在

RewriteEngine On

的RewriteCond $ 1!^子目录 的RewriteCond%{HTTP_HOST}!^ www.example.com $ [NC] 重写规则^(。*)$ http://www.example.com/ $ 1 [L,R = 301 ]

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

这篇关于htaccess的重定向非www到www,除了特定的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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