【问题标题】:htaccess www to non www does not work for sub directorieshtaccess www 到非 www 不适用于子目录
【发布时间】:2012-06-01 03:06:07
【问题描述】:

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

请指导我。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

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

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

    【讨论】:

    • +1 建议避免混淆 mod_alias 和 mod_rewrite。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 2014-07-24
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 2019-01-28
    • 2021-02-12
    相关资源
    最近更新 更多