htaccess www到非www不适用于子目录

时间:2012-05-25 14:14:35

标签: .htaccess

我正在使用以下.htaccess代码。

根文件夹中的

.htaccess

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

#temporary redirect root to dir/
RedirectMatch ^/$ /dir/
dir文件夹中的

.htaccess

RewriteEngine  on
#for changing index file to a custom one
DirectoryIndex abc.php?tag=ho

#for simple url
RewriteRule ^what/([^/]*)\.html$ /dir/abc.php?tag=$1 [L]

使用当前代码www.domain.com重定向到domain.com但www.domain.com/dir/不会重定向。

我需要修改两件事:

  1. 将www重定向到非wwww
  2. 将domain.com重定向到domain.com/dir /
  3. 请指导我。

1 个答案:

答案 0 :(得分:1)

组合Redirect(匹配)和rewriterule会遇到麻烦。而不是使用RedirectMatch:

RewriteCond $1 !^dir/
RewriteRule ^(.*)$ /dir/$1 [R=301,L]