【问题标题】:Redirect entire directory with htaccess使用 htaccess 重定向整个目录
【发布时间】:2014-01-07 22:25:35
【问题描述】:

我无法弄清楚为什么我的重定向无法正常工作,因为它们在另一个 htaccess 文件中。

我正在尝试将旧网址重定向到新网址。


RewriteEngine on
AddDefaultCharset UTF-8

DirectoryIndex index.php index.html
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
</IfModule>

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule (.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1

RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

Redirect /private_3 http://website.com/new_private

我尝试了各种我在网上找到的东西,但没有任何效果。

请帮忙。

谢谢。

【问题讨论】:

  • 哪个 URL 没有重定向?
  • 在提出问题时,请始终非常清楚什么不起作用。 “没有任何效果”从来都不是一个好的问题描述。在这种情况下:您是否收到错误消息?你有白屏吗?浏览器没有重定向吗?它是否重定向到错误的网址?列出您尝试过的 url 以及输入这些 url 时的结果、.htaccess 所在的位置(相对于您网站的 www-root)以及您是否测试了 mod_rewrite 是否实际启用(确实RewriteRule ^foo$ /bar [R,L] 重定向你?)。您所说的另一个 .htaccess 文件是什么?

标签: apache .htaccess mod-rewrite http-status-code-301


【解决方案1】:

而不是使用这个:

Redirect /private_3 http://website.com/new_private

尝试在RewriteEngine on 行的正下方添加这个

RewriteRule ^private_3(.*)$ http://website.com/new_private$1 [L,R=301]

【讨论】:

    【解决方案2】:

    mod_aliasmod_rewrite 的排序和混合看起来很糟糕,这可能是个问题。尝试重新排序您的规则:

    AddDefaultCharset UTF-8
    
    DirectoryIndex index.php index.html
    <IfModule mod_php.c>
       php_flag magic_quotes_gpc off
    </IfModule>
    RewriteEngine on
    
    RewriteRule ^private_3 http://website.com/new_private [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    
    RewriteRule ^(system.*)$ index.php?/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1
    

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多