Forum Moderators: phranque

Message Too Old, No Replies

WP htaccess directory remapping

         

agneslesage

2:24 pm on Sep 14, 2010 (gmt 0)

10+ Year Member



Hello
I would like to sollicitate another help from the htaccess gurus here.

I am using WP and e-commerce plugin, where each product is under category/subcategory/product type or URL, and I now have to flatten it because one subcategories is moving to the root.

So I have UTL like
[mysite.com...]
[mysite.com...]
[mysite.com...]
(and more)
moving to:
[mysite.com...]
[mysite.com...]
[mysite.com...]

Is there a way to redirect those without writing each of them?

Thanks
Agnes

agneslesage

2:29 pm on Sep 14, 2010 (gmt 0)

10+ Year Member



Sorry is better with the codes!

Hello
I would like to sollicitate another help from the htaccess gurus here.

I am using WP and e-commerce plugin, where each product is under category/subcategory/product type or URL, and I now have to flatten it because one subcategories is moving to the root.

So I have URL like

http://www.mysite.com/traiteur/buffets-et-cocktails/buffets/product1
http://www.mysite.com/traiteur/buffets-et-cocktails/buffets/product2
http://www.mysite.com/traiteur/buffets-et-cocktails/buffets/product3
(and more)

moving to:

http://www.mysite.com/traiteur/buffets/product1
http://www.mysite.com/traiteur/buffets/product2
http://www.mysite.com/traiteur/buffets/product3

And I also have

http://www.mysite.com/traiteur/plateaux-cocktails/product1
http://www.mysite.com/traiteur/plateaux-cocktails/product2
http://www.mysite.com/traiteur/plateaux-cocktails/product3
(and more)

moving to:

http://www.mysite.com/traiteur/cocktails/product1
http://www.mysite.com/traiteur/cocktails/product2
http://www.mysite.com/traiteur/cocktails/product3


Is there a way to redirect those without writing each of them?

Thanks
Agnes

PS:I really widh e-commerce plugin would enable to use some kind of permalink system where a change in catalog bdoes not have to impact URL...

jdMorgan

11:00 pm on Sep 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, but what have you tried so far, based on what you've learned here?

Jim

agneslesage

8:38 am on Sep 15, 2010 (gmt 0)

10+ Year Member



I see I see.. this is not just a self-service free advice board, there is a serious dissemination of knowledge to take place!

I ve got this, I've tried on my localhost:

RewriteRule buffets-et-cocktails/buffets$ http://www.mysite.com/traiteur/buffets [R=301,L]
RewriteRule buffets-et-cocktails/cocktails$ http://www.mysite.com/traiteur/cocktails [R=301,L]
RewriteRule ^plateaux-cocktails http://www.mysite.com/traiteur/cocktails [R=301,L]

But it does not redirect at all (thus error 404) I am not sure why:-(
And even if it would, it would do so only for requests ending with these things, so not all products attached behind

Now, if I want to have "all products behind" I should probably do sthg with "?", but the examples I got were for query strings, not normal URL

RewriteCond %{QUERY_STRING} ^([^&]*&)*page=qui_nous(&.*)?$
RewriteRule ^template\.asp$ http://www.mysite.com/qui-sommes-nous/? [R=301,L]


So I dont know... Should I do like:

RewriteCond ^traiteur/buffets-et-cocktails/buffets?
RewriteRule http://wwww.mysite.com/traiteur/buffets? [R=301,L]

But it gives error 500!

agneslesage

8:52 am on Sep 15, 2010 (gmt 0)

10+ Year Member



I am also checking some documentation and also try something simpler...

RedirectPermanent /buffets-et-cocktails/buffets http://www.mysite.com/traiteur/buffets

Which I place before the WP block in a simple htaccess file... also no effective (no redirect and then error 404).
But now I am lost because even a simple rule I had befire, and I place there, does not work (no redirect, error 404). So must be my way to place instruction that is wrong?
pfff.
For some reason I va alsways had to have a simpler version on my localhost, because my online elaborate version does not work locally... and then I get lost.

What I have now:

RewriteEngine on
RedirectPermanent /buffets-et-cocktails/buffets http://localhost/www.atable-new.com/traiteur/buffets
RewriteRule ^le-lunch-bag-sac-pique-nique http://localhost/www.atable-new.com/traiteur/coffrets-repas/les-lunch-bags/


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www.atable-new.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www.atable-new.com/index.php [L]
</IfModule>
# END WordPress

jdMorgan

5:04 pm on Sep 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



http://www.example.com/traiteur/buffets-et-cocktails/buffets/product1
http://www.example.com/traiteur/buffets-et-cocktails/buffets/product2
http://www.example.com/traiteur/buffets-et-cocktails/buffets/product3
to:
http://www.example.com/traiteur/buffets/product1
http://www.example.com/traiteur/buffets/product2
http://www.example.com/traiteur/buffets/product3

 RewriteRule ^traiteur/buffets-et-cocktails/buffets/(.+)$ http://www.example.com/traiteur/buffets/$1 [R=301,L]

The ".+" pattern can and should be made more specific --for example "[^/]+"-- but it depends on the exact character-set used (and allowed) in "product1" names.

Jim

agneslesage

9:41 am on Sep 16, 2010 (gmt 0)

10+ Year Member



Thanks Jim, I'll try that right now.
the character-set used is.... utf-8, with no accents and some "-"
So basically we have nice food names there, like "specialites-italiennes", "plateaux-de-douceurs-et-petits-fours", and alike!
Agnes

agneslesage

9:51 am on Sep 16, 2010 (gmt 0)

10+ Year Member



That works! (well you won't( be surprised, but for me it is always a pleasure)
Would there be a way to include into the same rule that the root directory is also redirected, ot should I add:
RewriteRule ^traiteur/buffets-et-cocktails/buffets http://www.example.com/traiteur/buffets [R=301,L]

agneslesage

10:57 am on Sep 16, 2010 (gmt 0)

10+ Year Member



In fact, I now had to add 2 and end up with 3 rules, I am quite hoping that could be simplified, no?
NB: these rules are before the other WP-type of rules with /index and co...


RewriteRule ^traiteur/buffets-et-cocktails/buffets(.+)$ http://www.atable.com/traiteur/buffets$1 [QSA,L]
RewriteRule ^traiteur/buffets-et-cocktails/buffets http://www.atable.com/traiteur/buffets [QSA,L]
RewriteRule ^traiteur/buffets-et-cocktails/buffets/ http://www.atable.com/traiteur/buffets [QSA,L]

jdMorgan

3:41 pm on Sep 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Only one rule is needed if you use the power of regular expressions:

RewriteRule ^traiteur/buffets-et-cocktails/buffets((/[^/]+)*)/?$ http://www.atable.com/traiteur/buffets$1 [R=301,QSA,L]

Do note that I re-included [R=301] flag. If you omit this, you may badly damage your search rankings.

Jim

agneslesage

1:25 pm on Sep 24, 2010 (gmt 0)

10+ Year Member



Thanks a lot Jim, I'll try that!
(now relocating to Lesotho... almost out of the web!)
Agnes

jdMorgan

2:30 pm on Sep 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fascinating -- The only country that is entirely inside another country!

Jim

agneslesage

2:37 pm on Sep 27, 2010 (gmt 0)

10+ Year Member



... and the highest country in the world! Is is almost entirely a mountain, and the relative stress of the tiny capital seems sharp when you see the countryside....

agneslesage

9:09 am on Sep 28, 2010 (gmt 0)

10+ Year Member



Done. It all works fine.
Thanks, Jim!

Sometimes I wonder what you really do in life beside free support to dummies like me....

jdMorgan

3:03 pm on Sep 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Help people and companies with more difficult problems, or problems that are larger in scope.

Not very many from Lesotho, though... :)

Jim

agneslesage

9:28 am on Sep 29, 2010 (gmt 0)

10+ Year Member



I am sure you did not know you had one in Zimbabwe neither (that was me!). Lost in the African web...

g1smd

11:20 am on Sep 29, 2010 (gmt 0)

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



WebmasterWorld truly covers the world! :)