2012-05-25 68 views
0

我正在使用以下.htaccess代碼。htaccess www到非www不適用於子目錄

在根文件夾的.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/

請指引我。

回答

1

將重定向(匹配)和重寫過程結合在一起會造成麻煩。而不是您的RedirectMatch使用:

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

+1建議避免混合mod_alias和mod_rewrite。 – anubhava