0

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

.htaccess 在 dir 文件夹中

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/

请指导我。

4

1 回答 1

1

结合 Redirect(match) 和 rewriterule 是自找麻烦。而不是您的 RedirectMatch 使用:

RewriteCond $1 !^dir/
RewriteRule ^(.*)$ /dir/$1 [R=301,L]
于 2012-05-25T19:16:19.197 回答