Forum Moderators: phranque

Message Too Old, No Replies

Redirect specific file name to containing folder

page.htm to folder

         

Naveenn

2:18 pm on Jun 12, 2012 (gmt 0)

10+ Year Member



Hi,

I am moving my static html site to wordpress, in this process I wont be able to save all file. However I am keeping the folder url structure with the help of permalinks. I need to redirect specific pages to the main folder permalink. Let me explain.

Current Structure
domain.com/member-1/bio.htm
domain.com/member-1/stats.htm

domain.com/member-2/bio.htm
domain.com/member-2/stats.htm

and 100 more members like that.


I need to redirect all bio.htm and stats.htm to member url link. i.e


domain.com/member-2/stats.htm to domain.com/member-2/
domain.com/member-2/bio.htm to domain.com/member-2/


for each member.

Please Help.
Regards,
Naveen

g1smd

5:39 pm on Jun 12, 2012 (gmt 0)

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



Use a RewriteRule for each group of URLs. The target URL will contain protocol and domain name. The rule will need the [R=301,L] flags.

There's more than 20 000 previous threads with examples of redirects of various sorts. Let's see your code.

Naveenn

6:12 pm on Jun 12, 2012 (gmt 0)

10+ Year Member



Well I did try few of the code available here and there but did not work well for me. Also I don't think it's necessary to make RewriteRule for each group as a single piece of code can do the trick.

g1smd

8:16 pm on Jun 12, 2012 (gmt 0)

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



Let's see the code you tried. Describe what it should have done, what it actually did and how that differs from what you expected.

Naveenn

9:03 pm on Jun 12, 2012 (gmt 0)

10+ Year Member



Well, if I understood how it worked, I would have not posted this question. Anyways. This is what I tried, didn't work for me.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^bio\.htm$ /? [R=301,NE,NC,L]
RewriteRule ^stats\.htm$ /? [R=301,NE,NC,L]

g1smd

10:14 pm on Jun 12, 2012 (gmt 0)

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



Remove the NE flag.

The RewriteCond applies only to the next rule that follows it. It says to redirect requests for bio.html without a query string and don't redirect requests with a query string. Is that what you want?

The rule target should include protocol and domain name, not just the new path.

The last RewriteRule redirects requests for stats.htm to a new URL. Requests with or without parameters are redirected, but the new URL is always without parameters.

So, how does that differ from what you wanted to do?


Add a blank line after every RewriteRule to make the code easier to read. Use example.com in this forum to prevent URL auto-linking.