Redirect subfolder to root domain

北城余情 提交于 2020-01-05 07:33:32

问题


I want to redirect the subfolder and allcontents to root domain.

For example:

http://www.example.com/ubb/ will redirect to http://www.example.com

I put the .htaccess on ubb folder and the code is:

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

However when you access http://www.example.com/ubb/threads.php it will redirect to http://www.example.com/threads.php it should be http://www.example.com

Is there any code to try or other possible solution?


回答1:


Place this rule in /ubb/.htaccess:

RewriteEngine On
RewriteBase /ubb/

RewriteRule ^ /? [R=302,L]

Also test it out in a different browser to avoid existing browser caches.




回答2:


It's achievable using PHP which will be quiet easier I believe.

Create index.php inside ubb folder & add this code to it.

index.php

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

It'll redirect all request coming to www.example.com.



来源:https://stackoverflow.com/questions/24630242/redirect-subfolder-to-root-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!