htaccess通配符重定向

时间:2012-03-21 13:34:50

标签: .htaccess redirect

我想将我的所有文件和文件夹(目录)从www.example.com/*重定向到www.example.com/website/。我现在的.htaccess是:

RewriteEngine on

# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini

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

然而它无效。

1 个答案:

答案 0 :(得分:2)

RewriteCond %{REQUEST_URI} !^/website/
RewriteRule ^.*$ http://www.example.com/website%{REQUEST_URI} [R=301,L]

小注意:我建议使用302代码进行测试,当您对结果感到满意时,将其更改为301(当然需要)。原因 - 现代浏览器会缓存301重定向..因此它可能已经有效,但您仍然可以看到缓存结果。

相关问题