简体   繁体   中英

Redirect subfolder to root domain

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?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM