Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   General Business Knowledge (http://www.greenguysboard.com/board/forumdisplay.php?f=10)
-   -   301 Redirect (http://www.greenguysboard.com/board/showthread.php?t=72083)

Ramster 2021-03-01 01:56 PM

301 Redirect
 
Trying to redirect everything that comes into a folder, problem is it's often subfolders within it. Any ideas?

.htaccess:
RewriteRule ^/(.*)$ https://domain.com/site/$1 [L,R=301]

Placing it in domain.com/site/scene/ folder so when someone lands on domain.com/site/scene/757/1922/her-video they get redirected to just https://domain.com/site/

Anyone?

sarettah 2021-03-10 11:22 PM

Quote:

Originally Posted by Ramster (Post 563450)
Trying to redirect everything that comes into a folder, problem is it's often subfolders within it. Any ideas?

.htaccess:
RewriteRule ^/(.*)$ https://domain.com/site/$1 [L,R=301]

Placing it in domain.com/site/scene/ folder so when someone lands on domain.com/site/scene/757/1922/her-video they get redirected to just https://domain.com/site/

Anyone?

If you do not have any additional .htaccess files in the subfolders then that should work I would think. If it encounters another .htaccess along the way that will override, I believe.

I will test for a second and let you know.

sarettah 2021-03-10 11:48 PM

I set up a test at https://madspiders.com/htaccess_test/

In the root directory I have just an index.htm page that will show "Main Page".

I have a subfolder called subfolder1. in there is an .htaccess file that looks like this:

RewriteEngine On
RewriteRule ^(.*)$ ../

In there is also another index.htm page that if it gets hit will show "subfolder1"

So anything hitting there should be redirected to the main folder one step down. And it does that. https://madspiders.com/htaccess_test/subfolder1/

Inside of subfolder1 I have a subfolder called subfolder2. That has an index.htm page that will show "subfolder 2" if it gets hit. There is no .htaccess file in subfolder2.

So the .htaccess folder in subfolder1 controls the rules and subfolder2 never shows because the hit is redirected to the Main folder.

https://madspiders.com/htaccess_test...r1/subfolder2/

Inside subfolder2 I have a subfolder called (can you guess?, yeppir), subfolder3. That has an index page that when it gets hit will show subfolder 3. It also has an .htaccess file with just one line RewriteEngine Off

That turns off the redirect at that level and lets you see subfolder3.

https://madspiders.com/htaccess_test...r2/subfolder3/


So, like I say, you should be able to do the redirect of everything subfolders and all with just 1 htaccess file at the proper level.

Hope that helps and I hope it answered the question, lol. Hate to type that much and find out I misinterpreted the question.

.


All times are GMT -4. The time now is 08:24 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc