Welcome to WebmasterWorld Guest from 3.85.245.126

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 redirect help for moving to a subdomain

How do I get all the old links to point to new subdirectory?

     
2:39 pm on Jun 10, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 2, 2003
posts: 45
votes: 0


I am completely lost when it comes to writing more than the simplest 301 redirects, but I have just moved a Volusion store to a subdirectory (shop) from the www directory and want to redirect all my product and category pages to the new subdirectory pages.

The helpful thing about Volusion's crazy folder structure is that all products have a -p in their address (http://mysite.com/product-p/paft-number.htm)

My bad guess would be something like this:

redirect 301 *-p/* [shop.mysite.com...]

Where the stars are the wildcards?

Any ideas?

Thanks,

Don
6:20 pm on June 10, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


You need a bit more "detail" in the pattern matching.

How many slashes are there in each type of URL?
How many hyphens? Is it a fixed or variable number?

Don't use Redirect, use RewriteRule and the [R=301,L] flags.
6:53 pm on June 10, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15903
votes: 877


The helpful thing about Volusion's crazy folder structure is that all products have a -p in their address

Is the converse also true? Are they the only ones with "-p" in the address?

Your htaccess file will not, of course have wildcards as such. At a minimum, you will have either
.*
meaning "there may or may not be some stuff here"
or
.+
meaning "there will definitely be some stuff here, but I don't know how much".

But it's probably too much to hope that your search string can use the minimalist form
(.+-p/.*)
changed to
shop/$1

or even
(.+)-p(/.*)
changed to
shop/$1$2
if you're concurrently ditching the -p.

Better post a few examples-- using example.com so the url remains visible. (That is, we don't want to go to your site, but we need to see its exact address format :))
7:17 pm on June 10, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


It is a very rare occasion that .+ or .* is the right pattern.

This will need something a little more complex, based on the answers to the questions several posts back.
7:50 pm on June 10, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 2, 2003
posts: 45
votes: 0


Thanks for all the help here. The hyphens are variable - I will make sure to never use -p in any of the new site's urls.

Here are a couple examples:

http://example.com/Market-Bag-Recycled-Plastic-p/pwmbb9.htm
http://example.com/Penguin-Egg-Cozy-p/pec246.htm


Any hope?
8:41 pm on June 10, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15903
votes: 877


And you're moving them to locations with the exact same name, plus /shop, minus -p?

The basic regex pattern is then

(/[\w\-]+)-p(/\w+\.htm)
goes to
/shop$1$2

wrapped in some formalities which g1smd will lay out ;) (This part depends on whether you're doing a redirect or a rewrite, and possibly on your server: mine for example doesn't demand a complete path even where apache says you have to.)
3:43 pm on June 12, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 2, 2003
posts: 45
votes: 0


Actually, I am not removing the -p, I was just thinking it was a good place to "anchor the search" (if that's a term anyone has ever used). I'm basically just going from (one of the product's examples):

http://example.com/Penguin-Egg-Cozy-p/pec246.htm
or
http://www.example.com/Penguin-Egg-Cozy-p/pec246.htm

to:

[shop.example.com...]

I just moved the old site to a subdomain. I assume a RewriteRule is in order here - And thank you for the help, lucy24, but can you be one step more specific on the code - this is _way_ over my head...

Thanks for the help!
4:12 pm on June 12, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


One way to deal with any number of folders (including zero) followed by a filename with extension is:
^(([^/]+/)*)([^/.]+)\.html$
and extensionless is even more simple:
^(([^/]+/)*)([^/.]+)$
5:32 pm on June 12, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15903
votes: 877


I'd make it

^((?:[^/]+/)*)([^/.]+)
or simply (omitting the open-and-close parentheses since they're not needed for separate captures)
^(([^/]+/)*[^/.]+)

to avoid generating a superfluous $2 that you then have to keep track of. Or does Apache's dialect of RegEx not do nested captures?

Actually, I am not removing the -p, I was just thinking it was a good place to "anchor the search" (if that's a term anyone has ever used).

Oh, that's fine, just include it in your capture then. You really are lucky to have a unique search string. But you can't simply have

(.+-p.+)
changing to
shop/$1

because you have to allow for users who were here yesterday and bookmarked the address with the "shop/" piece, so you don't end up with your server frantically looking for

shop/shop/shop/shop/blahblah-p/blahblah...

:)

In English, what you want to do is:

If the original address contains "-p" but does not start with "shop/", then add "shop/".

Does it have to be a redirect or can you use rewrite instead? It then becomes easier to lay out the conditions. I think (g1? you out there?) it goes like this:

RewriteCond %{REQUEST_URI} !^shop/
RewriteCond %{REQUEST_URI} -p
RewriteRule (.+\.html) shop/$1 [R=301,L]

In English:
IF your user requests a page which
does not (! means no) begin with (^ means beginning) "shop/"
AND (groups of rules carry an implied "and" unless you specify [OR])
does contain (if you don't have any anchors, the text just has to be in there somewhere) the element -p

THEN
grab their whole request (the part you put in parentheses), shove a "shop/" in front, and put back the original request
AND ALSO
make it a 301 Redirect (if you don't have the R=301 piece, the user will physically end up at the right page but their browser's address won't change, and search engines won't know that you've moved)
AND FINALLY
proceed directly to the page and don't waste any more time on the .htaccess page (if you leave out the L, the code will continue looking for any other rules that might apply)

except that I may have put the / on the wrong side of "shop"
12:44 am on June 15, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 2, 2003
posts: 45
votes: 0


Thank you for the amazing help here... really.

But, sadly I kept getting a "The page isn't redirecting properly" error.

I tried moving the / around both sides of "shop" and it didn't help - I also noticed there was a reference to .html, when the files are .htm, so I changed that.

I am thinking I will just make a very nice page not found page...

Also, was wondering, if this did work, would it also capture (by mistake) any new www. pages that have a -p (like a page about pickled-peppers)?

Thanks again,
Don
4:21 am on June 15, 2011 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:15903
votes: 877


Also, was wondering, if this did work, would it also capture (by mistake) any new www. pages that have a -p (like a page about pickled-peppers)?

Good thought :) In your original files, you've always got the -p at the end of a directory name, not followed by any more text. So you need to make sure the rewrite conditions pick up only addresses in that form. If you're capturing the whole last part of the request, you've already got the sequence -p/ which is what you want. Just remember never to make any new directories called, say, "morestuff-a", "morestuff-b", and so on until you hit "morestuff-p" ;)

!Whoops! Have you got any rewrites in your htaccess from before? If not, you need to start with a single

RewriteEngine on

to make them work. Just once, not a fresh one for each rewrite.

I am thinking I will just make a very nice page not found page...

Well, having a custom 404 page (also a custom 403 and maybe others) is a good thing in any case. Let it match the look and feel of the site, and include a few links to useful places like the front page. Just remember that a 404 page is really a special kind of rewrite, so links have to be absolute. They can't be based on where the 404 page is physically located, because the server thinks you're somewhere else.

The only problem with a custom 404 is that it's only helpful for humans. Robots will keep trying to crawl the original location, no matter how many times they run into a 404. Humans tend to give up after 3 or 4 tries. Robots keep trying forever.

:: looking vaguely around for g1smd or someone like him ::