Welcome to WebmasterWorld Guest from 54.144.77.26

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Remove folder from URL and redirect to parent

     

imofloripa

1:50 pm on Sep 22, 2010 (gmt 0)



Hello Guys,

i am in a big trouble due to some upgrade to the friendly url component i am using for my site.

My links ofreal estate properties were something like this:

apartment/new-york/apartment-in-new-york-with-3-bedrooms/my-properties

now i updated the component and they finally removed the ugly /my-properties from the end of all urls.

Result of this, all my google indexed urls are 404.

Is there a way to remove the /my-properties from the end of urls and redirect it to parent folder?

the problem is that the parent folder always changes, any property has a different folder name and then the /my-properties appended,

i red tons of articles about htaccess, and nothing. I dont want to insert something like 300 redirect rules in htaccess in order to redirect all old pages of properties for sale, and i am desperate, can somebody help me to remove or redirect this /my-properties from URLs and reidrect to parent folder?

thanks a LOT...

g1smd

2:21 pm on Sep 22, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



One line of code should do it, using RewriteRule, a pattern like (([^/]+/)+)my-properties, and the [R=301,L] flags. State the protocol and domain name as the target and append the $1 backreference for the variable part of the URL.

What have you tried so far?

imofloripa

2:35 pm on Sep 22, 2010 (gmt 0)



man, can you please send me the line of the code as i need to put it in htaccess? i tried to paste a lot of things i found on forums, but i am not an apache programmer, can you PLEASE send me a line of code to put there?

imofloripa

4:13 pm on Sep 22, 2010 (gmt 0)



please, anybody can help, i am having trouble at work, can somebody send me a pieace of code to put in htaccess with the directives that the user g1smd sent here? i am not able to format it alone..... pleaseeeee

imofloripa

4:38 pm on Sep 22, 2010 (gmt 0)



ok guys, i used

RewriteRule (([^/]+/)+)my-properties http://www.mysite.com.br/$1 [R=301,L]


and it worked.

now it generated another problem for me. There are still some urls that contains the /my-properties/ folde in them, but not at the end of the url, but in the middle.

With this rule, all these URLs are 404.

Ex. mysite.com/itajai/my-properties/showstate

becomes

mysite.com/itajai/

so the rule above removes everything after the /my-properties/ and i still have a lot of 404.

My question: is there any way to modify this rule in order to delete the /my-properties/ only if it is positioned at the very END of the url? not if it has something after it, like here?

mysite.com/itajai/my-properties/showstate

Thanks a lot!

g1smd

5:00 pm on Sep 22, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month




There's two ways to tackle this.

1. Append the $ end-anchor to the end of the pattern.

OR

2. Append /(.*) to the end of the pattern, and $2 or /$2 to the end of the target.

You'll need to test whether $2 or /$2 is the right one.

imofloripa

5:18 pm on Sep 22, 2010 (gmt 0)



like this?

RewriteRule (([^/]+/)+)my-properties/(.*) http://www.mysite.com.br/$2 [R=301,L] 

g1smd

11:55 pm on Sep 22, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Append is not replace.

jdMorgan

1:31 pm on Sep 23, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member




RewriteRule ^(([^/]+/)+)my-properties(/.*)?$ http://www.mysite.com.br/$1$2 [R=301,L]

Jim

imofloripa

1:42 pm on Sep 23, 2010 (gmt 0)



thanks Jim..... a lot.....