使用htaccess重定向整个目录

时间:2014-01-07 14:16:21

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

我无法弄清楚为什么我的重定向无法正常工作,因为它们位于另一个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

我尝试过各种各样的东西,我在网上找到但没有任何作用。

请帮忙。

感谢。

2 个答案:

答案 0 :(得分:0)

而不是使用它:

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

尝试在RewriteEngine on行下面添加此

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

答案 1 :(得分:0)

查看错误的排序,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