Forum Moderators: phranque

Message Too Old, No Replies

Redirecting Sub-Directories (root only)

category

         

tfweb

4:20 pm on Jul 2, 2014 (gmt 0)

10+ Year Member



I am looking to redirect mysite.com/shoes/ to mysite.com/all-shoes/ while keeping all existing lower-categories the way it is.

Example
mysite.com/shoes -> mysite.com/all-shoes/
mysite.com/shoes/women -> (remains the same)

Can someone please help me out with this?

Thanks a million in advance!

lucy24

7:24 pm on Jul 2, 2014 (gmt 0)

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



What have you tried so far?

:: insert "why we make you do it yourself" boilerplate ::

You'll need something using Regular Expressions so you can include the
$
ending anchor in the pattern. This can be done with either mod_rewrite (RewriteRule...) or mod_alias (RedirectMatch), depending on which one you're already using. Don't mix them!

Is the existing URL
/shoes
or
/shoes/
? You can write a rule that covers both, but make sure the target collapses to a single form.

tfweb

4:23 pm on Jul 4, 2014 (gmt 0)

10+ Year Member



Hi lucy24,

Thanks for your input.

Well, to be frank, I only tried doing the following:

Redirect 301 /shoes [mysite.com...]

Then I noticed I was just being stupid at that point, because it was redirecting the lower-categories too.

I now have my .htaccess open and it seems like my previous developer has been using RewriteRule, so like you suggested, I tink i should continue with that trend.

The existing URL is /shoes (not / after that).

Hope you can help. Thanks!

lucy24

8:40 pm on Jul 4, 2014 (gmt 0)

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



Yes, if any of your existing redirects use mod_rewrite, you have to use it for everything. Not because mixing mods will break your server, but only because things won't happen in the intended order.

All you need is a closing anchor

RewriteRule ^shoes$ et cetera


Note that in mod_rewrite in htaccess*, you don't begin with a slash. Place the rule among your other external redirects (the ones with [R=301,L] flag).

Question: What currently happens if someone requests
/shoes/
with trailing slash and nothing more? The mere fact that you're using extensionless URLs means there's rewriting going on, so it isn't a physical directory. But you have to deal with trailing-slash requests somehow, if only because search engines will try alternate forms in hopes of sniffing out Duplicate Content.


* Also in <Directory> sections in config. But generally by the time people set up their own servers, they've got this kind of thing internalized. Generally. Not always.