htaccess www to non www 不适用于子目录



我正在使用以下.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/

.ht 目录文件夹中的访问

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/

请指导我。

将重定向(匹配)和重写规则结合起来是自找麻烦的。而不是使用重定向匹配:

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

最新更新