Forum Moderators: phranque

Message Too Old, No Replies

301 redirect all folder index.php to folder root

301 redirect all folder main file index.php to respective folder root

         

Rajiv

1:13 pm on Sep 17, 2008 (gmt 0)

10+ Year Member



Hi Everybody.. I have a redirect problem.. Please help.. Here is the situation:

Recently I've renamed few folders and file names. They already have a good rankings, and hence I wish to use 301 redirect.

I want to redirect the following URL possibilities:

www.domain.com/oldfolder1/
www.domain.com/oldfolder1/index.php
www.domain.com/oldfolder1/index/

to

www.domain.com/newfolder1/

Likewise I also want:
www.domain.com/newfolder1/index.php
www.domain.com/newfolder1/index/

to be redirected to

www.domain.com/newfolder1/

Thank you very much!
Regards
Raj

jdMorgan

1:33 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Rajiv,

Please post the code you've tried as a basis for discussion. More information and links to basic resources can be found in our Apache Forum Charter [webmasterworld.com].

There are also many examples of /index to "/" redirects already posted in this forum -- Try a WebmasterWorld site search (See the Search, Library, and Charter links at the top of this page).

Thanks,
Jim

Rajiv

2:37 pm on Sep 17, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Thank you very much for your reply. I've been using the basic code for the redirect:

Redirect 301 /oldfolder1/index.php http://www.example.com/newfolder1/

The problem is that I have 30 such folders and more than 200 files..

So, let me know if I need to post this topic elsewhere?

Thank you once again.
Regards,
Rajiv

[edited by: jdMorgan at 3:46 pm (utc) on Sep. 18, 2008]
[edit reason] example.com [/edit]

g1smd

2:44 pm on Sep 17, 2008 (gmt 0)

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



You'll need to use RewriteRule and RewriteCond from Mod_Rewrite because some of your redirects are conditional on what was requested.

The code you need gets posted almost every other day, somewhere in WebmasterWorld.

jdMorgan

2:53 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's one example: [webmasterworld.com...]

Jim

Rajiv

2:53 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Thank you for the replies and help. For now I've decide to use the basic redirection like:

redirect 301 /old/old.htm to http://www.example.com/new/new.htm

but I am facing a problem. Here is the situation.. I have 2 redirect statements/lines as below in the .htaccess file:

redirect 301 /programA/ http://www.example.com/newprogramA/
redirect 301 /programA/locationA/ http://www.example.com/newprogramA/location-A/

Here, the second URL (the second line)
/programA/locationA is not redirected to /newprogram/location-A

instead it is redirecting to
/newprogram/locationA
which is a 404

The issue is that the sub folder /locationA/ is automatically appended to the landing page/path, instead of picking the URL mentioned.

Hope I am clear.
Thank you !
Regards
Rajiv

[edited by: jdMorgan at 3:47 pm (utc) on Sep. 18, 2008]
[edit reason] example.com [/edit]

jdMorgan

3:15 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See RedirectMatch. It will do what you want. Put the most-specific redirects first.

Jim

g1smd

4:12 pm on Sep 18, 2008 (gmt 0)

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



Also think about what you wrote in your example code.

The first rule always matches (because it begins with the path you mentioned) so that one is processed. The second one never gets looked at.

Swapping the order, would also (at least partially) solve the problem. Put the most specific stuff first.

jdMorgan

4:31 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem is that the Redirect directive appends any part of the requested URL that is not specified in the prefix-match to the substitution URL. This is the documented behavior of the Redirect directive, and is exactly what Rajiv reports seeing.

Jim