301将.htaccess从文件夹重定向到root

时间:2016-08-27 08:03:19

标签: apache .htaccess mod-rewrite url-redirection

我需要将所有网址从子文件夹重定向到root:

http://www.example.com/blabla/some-url
to
http://www.example.com/some-url 

我的.htaccess代码是:

RewriteCond %{HTTP_HOST} ^http\:\/\/www\.example\.com\/blabla$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/" [R=301,L]

但不适合我!

2 个答案:

答案 0 :(得分:1)

您正在匹配错误的参数。

RewriteEngine On
RewriteRule ^/?blabla/(.*)$ /$1 [R=301,L]

答案 1 :(得分:0)

您也可以使用RedirectMatch指令

RedirectMatch 301 ^/folder/(.+)$ http://example.com/$1

这将301重定向 / folder / foobar / foobar