将子文件夹重定向到根域

时间:2014-07-08 11:07:47

标签: php apache .htaccess mod-rewrite redirect

我想将子文件夹和所有内容重定向到根域。

例如:

http://www.example.com/ubb/会重定向到http://www.example.com

我把.htaccess放在ubb文件夹上,代码是:

RewriteEngine On
RewriteRule ^.*$ / [R=302,L]

但是当您访问http://www.example.com/ubb/threads.php时,它会重定向到http://www.example.com/threads.php它应该是http://www.example.com

是否有任何代码可以尝试或其他可能的解决方案?

2 个答案:

答案 0 :(得分:2)

将此规则放在/ubb/.htaccess

RewriteEngine On
RewriteBase /ubb/

RewriteRule ^ /? [R=302,L]

还要在其他浏览器中测试它以避免现有的浏览器缓存。

答案 1 :(得分:1)

使用PHP可以实现,我相信它会更安静。

index.php文件夹中创建ubb&将此代码添加到其中。

<强>的index.php

<?php
header('Location: http://www.example.com/');
?> 

它会将所有请求重定向到www.example.com