【问题标题】:.htaccess redirect to a sub directory not working right.htaccess 重定向到无法正常工作的子目录
【发布时间】:2013-06-21 17:24:22
【问题描述】:

我是 htaccess 的新手,我整天都在研究它。请帮忙。我只想:

  1. www.example.com 被重定向到 example.com/hu
  2. example.com 被重定向到 example.com/hu

这是我从typo3网站复制的htaccess文件:

<FilesMatch "\.(js|css)$">
  <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 7 days"
  </IfModule>
  FileETag MTime Size
</FilesMatch>


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^typo3$ typo3/index_re.php [L]




RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]

</IfModule>


RewriteCond %{HTTP_HOST} !^dnaplus-humangenetikaicentrum\.com$
RewriteRule ^(.*)$ http://dnaplus-humangenetikaicentrum.com/hu/$1 [L,R=301]

它将 www.example.com 重定向到 www.example.com/hu。但不适用于 example.com。

【问题讨论】:

    标签: .htaccess redirect mod-rewrite subdirectory


    【解决方案1】:

    试试这个

    # if hostname starts with "www"...
    RewriteCond %{HTTP_HOST} ^www\.(.+)$    #here we get rest of URI as %1
    
    # ...redirect permanently to hostname whitout "www":
    RewriteRule (.*) http://%1/$1 [R=301,L]
    
    
    # if client requested root directory:
    RewriteCond %{REQUEST_URI} ^/$
    
    # redirect him to start page:
    RewriteRule .* hu [R=307,L]
    

    我建议使用完全临时重定向 (307) 来启动页面。 301状态是浏览器硬缓存的,所以如果你稍后改变你的起始页面,一些用户仍然会被重定向到旧页面。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 2013-11-04
    • 2023-04-02
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多