问题
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