|Remove folder from URL and redirect to parent|
| 1:50 pm on Sep 22, 2010 (gmt 0)|
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:
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...
| 2:21 pm on Sep 22, 2010 (gmt 0)|
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?
| 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?
| 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
| 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.
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?
Thanks a lot!
| 5:00 pm on Sep 22, 2010 (gmt 0)|
There's two ways to tackle this.
1. Append the $ end-anchor to the end of the pattern.
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.
| 5:18 pm on Sep 22, 2010 (gmt 0)|
RewriteRule (([^/]+/)+)my-properties/(.*) http://www.mysite.com.br/$2 [R=301,L]
| 11:55 pm on Sep 22, 2010 (gmt 0)|
Append is not replace.
| 1:31 pm on Sep 23, 2010 (gmt 0)|
RewriteRule ^(([^/]+/)+)my-properties(/.*)?$ http://www.mysite.com.br/$1$2 [R=301,L]
| 1:42 pm on Sep 23, 2010 (gmt 0)|
thanks Jim..... a lot.....