Forum Moderators: phranque

Message Too Old, No Replies

301 redirect from a folder to sub folder of the previous folder

301 redirect from a folder to sub folder of the previous folder

         

lagentok

1:11 pm on Sep 26, 2007 (gmt 0)

10+ Year Member



Hello,

Does anyone have a solution about 301 redirection from a folder to the folder's sub folder?
Example :
From [mydomain.com...] to [mydomain.com...]

I would like all files inside the /blog/ folder being redirected to /blog/subfolder.

Thank you for your help.

g1smd

10:27 am on Sep 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to explain that a bit more.

Where are the files located in the server filesystem now?

What URL do you want to show the visitor?

Are you sure you want a redirect, or is it a rewrite that you actually require?

Defining exactly what you want is very important.

lagentok

6:04 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



I got many files in a folder called /mydirectory.
I created a new folder called my subdirectory inside /mydirectory.

I would like redirecting all pages located to /mydirectory to /mydirectory/subdirectory.

My problem was that the redirection was working but was looping no stop. So when I added the line "RewriteCond %{THE_REQUEST}!subdirectory" apache server found the sub directory and stops looping.

Here is the solution I ve just found:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /mydirectory
RewriteCond %{THE_REQUEST}!subdirectory
RewriteRule (.*) [mydomain.com...] [R=301,L]
rewriterule subdirectory/(.*) /mydirectory/$1

The code above is working fine but if you have another suggestion let me know.

Thank you.

g1smd

6:43 pm on Sep 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So, the user now sees all the content at a new URL? That isn't always a good idea.

If you had used a rewrite, then you could have kept the same URLs for the user.