.htaccess redirect FROM subfolder to domain name

I had the website content in a subfolder ( http://mydomain.com/subfolder/index.php ), now I copied everything to the root folder ( http://mydomain.com/index.php ).

I would like to redirect all visitors who bookmarked the old page to new content (at least to the new index.php) using .htaccess.

Is it correct:

RewriteEngine on RewriteRule /subfolder/^(.*)$ http://mydomain.com [R=301,L] 

?

And where would I put the .htaccess file in a subfolder or in the root folder?

+7
source share
5 answers

Placing the following .htaccess in / (where your index.php is located) should do the trick:

 RewriteEngine on RewriteRule ^subfolder/(.*)$ /$1 [R=301,L] 

Or you can put the following .htaccess in /subfolder :

 RewriteEngine On RewriteRule ^(.*)$ /$1 [R=301,L] 

Note that () around .* And $1 redirects /subfolder/someFile.php to /someFile.php . If you skip it, everything in /subfolder redirected to / .

+27
source

Try:

 RewriteEngine On RewriteRule ^subfolder/index.php$ /index.php[NC,L,R] 
+1
source

Thanks to @mariusnn in the comments, I was able to solve this problem.


Working Doesn't work: .htaccess redirect from FROM subfolder to domain name

 RewriteEngine on RewriteRule ^subfolder/(.*)$ /$1 [R=301,L] 

Work : .htaccess redirects the entire subdomain "/ subdomain /", and the files "/subdomain/file_01.php" inside are redirected to the domain name "example.com"

 RewriteEngine on RewriteRule ^subfolder/.*$ / [R=301,L] 

* Note that () around .* And $1 redirects /subfolder/someFile.php to /someFile.php . If you skip this, everything in /subfolder redirect to / .

+1
source

I tried all the answers here. Here is what worked for me:

 RewriteEngine on RewriteBase / RewriteRule ^subfolder/(.*)$ /$1 [R=302,NC,L] 

Change R=302 to R=301 after you confirm the changes.

0
source

This does the trick:

 RedirectMatch 301 ^/subfolder$ http://yourdomain.tld/ 
0
source

All Articles