Forum Moderators: phranque

Message Too Old, No Replies

Tricky. Can't forward dynamic pages to new domain.

         

londonhogfan

7:59 pm on Aug 4, 2008 (gmt 0)

10+ Year Member



Hello,

I am trying to figure out a way to forward all links from my photo gallery which is located here.

http://www.example.com/hog_archive/

to my new domain. Here.

http://www.quux-foo.com/razorback-photos/

I have setup mod rewrite to have more SEO friendly urls on the new site, but I can't figure out if it's possible to auto send dynamic pages to the new domain without doing them 1 by 1. (which would be almost impossible since I have over 5,000 photos in the gallery) I can't find anything on the net about it so I don't even have a starting point.

http://www.example.com/hog_archive/index.php?cat=41
which is now
http://www.quux-foo.com/razorback-photos/index-41.html

http://www.example.com/hog_archive/thumbnails.php?album=272
now...
http://www.quux-foo.com/razorback-photos/thumbnails-272.html

http://www.example.com/hog_archive/displayimage.php?album=272&pos=0
is now
http://www.quux-foo.com/razorback-photos/displayimage-272-0.html

Can anyone help me out with this?

Thanks in advance.

[edited by: jdMorgan at 9:13 pm (utc) on Aug. 4, 2008]
[edit reason] Obscured specifics per Terms of Service [/edit]

jdMorgan

9:12 pm on Aug 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use mod_rewrite to do the redirects: Query strings are passed through mod_rewrite unchanged, unless you specifically change them.

Jim

londonhogfan

9:19 pm on Aug 4, 2008 (gmt 0)

10+ Year Member



Thanks.

I know this would rewrite the urls, but do you know how I could forward each of them to the new domain too?

RewriteEngine On
RewriteRule ^razorback-photos/index-([^/]*)\.html$ /hog_archive/index.php?cat=$1 [L]

jdMorgan

9:42 pm on Aug 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't want to mix those two functions. If you do, your dynamic back-end filepaths will be 'exposed' to search engines, and you'll end up with the dynamic URLs indexed, instead of the static ones.

Instead, if a dynamic URL is requested on the old domain, then redirect it to the static URL on the new domain. Then if a static URL is requested on the old domain, redirect that to the new domain directly. Example - in .htaccess on old domain:


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/thumbnails\.php\?album=([0-9]+)
RewriteRule ^hog_archive/thumbnails\.php$ http://www.quux-foo.com/razorback-photos/thumbnails-%1.html [R=301,L]
#
RewriteRule ^razorback-photos/thumnails-([0-9]+)\.html$ http://www.quux-foo.com/razorback-photos/thumbnails-$1.html [R=301,L]

Note that %1 and $1 differ in the two rules: Utterly intentional (and required).

If you have any dynamic URLs already indexed on the new domain, you'll also need the first rule on that server as well.

And finally, if both domains are actually located in the same filespace on the same server, and share this .htaccess file, you'll need to qualify the second rule by adding:


RewriteCond %{HTTP_HOST} !^www\.quux\.foo

so that the rule won't be invoked if the requested host is already "www.quux-foo.com" -- thus avoiding an infinite loop.

For the sake of efficiency, and again if both domains are actually located in the same filespace on the same server, you'll need to add that exclusion to your internal rewriterule that forwards static URLs to your dynamic filepaths. Internal rewrite rules should, in general, always follow external redirect rules.

BTW, the contents of %{THE_REQUEST} is the entire client HTTP request header, and might look like this:

GET /hog_archive/thumbnails.php?album=10 HTTP/1.1

This header is what you see in the quoted string in your raw server access log file. Hopefully, that will help clarify the seemingly-odd regex pattern I used above.

Jim

londonhogfan

1:18 am on Aug 5, 2008 (gmt 0)

10+ Year Member



Thank You for your help. I really appreciate it.

I put the code you wrote:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/thumbnails\.php\?album=([0-9]+)
RewriteRule ^hog_archive/thumbnails\.php$ [quux-foo.com...] [R=301,L]
#
RewriteRule ^razorback-photos/thumnails-([0-9]+)\.html$ [quux-foo.com...] [R=301,L]

into the .htaccess file which is in the hog_archive directory of the old domain. Then Changed www.quux-foo.com to my new domain, but I'm not seeing any change. When I click on one of the thumbnails.php pages it stays there instead of redirecting to the new server with the .html file names.

Also, Nothing has been indexed on the new server yet.

jdMorgan

1:51 am on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must adapt the RewriteRule pattern to the .htaccess file's directory level... in this case, by removing the first directory level from the pattern. The URL-paths 'seen' by RewriteRule are 'localized' to the current directory, and will not contain the path to that directory.

Do not change the RewriteCond pattern; Remember, it must match the request sent by the browser.

Jim

londonhogfan

1:14 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



I hate to show my ignorance, but you lost me on the last post :(

I added this to the .htaccess file in the hog_archive directory of the original domain...

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [quux-foo.com...] [R=301,L]

that works, but it doesn't send to the new urls. Just to the dynamic ones like are used on the original site.

[edited by: jdMorgan at 6:20 pm (utc) on Aug. 5, 2008]
[edit reason] examplified domain [/edit]

jdMorgan

1:52 pm on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If read very carefully, my second response covers this: Your code must first redirect the dynamic URLs from the old domain to the corresponding static URLs on the new domain, then redirect the remaining static URLs from the old domain to the new domain. Rule order is critical, and all of the details must be attended to.

Rather than addressing multiple possible scenarios, it would be good to know the answer to the implicit question I posted above: Are the old a new domains hosted separately, or are the in the same filespace on the same server? In other words, do they share the domain.com/.htaccess file?

Jim

londonhogfan

2:15 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



no they are on separate servers. I'm going to retry your second response... To clarify. [quux-foo.com...] refers to the new domain. Correct?

jdMorgan

2:28 pm on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. Sorry for the confusion, but we use "un-ownable" domains here both to prevent low-quality self-promotion posts, and more-importantly, to prevent threads here from out-ranking the sites they talk about for searches on the domain name(s)... :)

Reiterating an important point: URLs seen by RewriteRule in .htaccess are localized to the current .htaccess directory. That is, RewriteRule does not see the URL-path to "this" directory, only the remaining path. As a result, the pattern used in a RewriteRule must not require the path to "this" .htaccess directory. The code I posted above was intended for use in the root .htaccess file, which is why it failed when moved to a subdirectory -- the path to that subdirectory was no longer present in the URL-path 'seen' by RewriteRule.

Jim

londonhogfan

5:44 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



ok, First let me thank you again for the time you have given to helping me.

I have been unable to get the problem fixed. I re-read your 2nd post and tried my best to follow your directions. I even had someone else read it with me so I wouldn't miss anything. I'm afraid I may not understand well enough to see what your getting at.

I have a .htaccess file in the public_html directory of the original domain as well as the hog_archive (photo gallery) directory. I have not input anything into the .htaccess file on the new domain and I have removed the changes I made to the .htaccess file in the gallery folder of the original domain.

I have put the code you listed in the 2nd post into the original domain's public_html .htaccess file only changing the "http://www.quux-foo.com" to the new domain name.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/thumbnails\.php\?album=([0-9]+)
RewriteRule ^hog_archive/thumbnails\.php$ [quux-foo.com...] [R=301,L]
#
RewriteRule ^razorback-photos/thumnails-([0-9]+)\.html$ [quux-foo.com...] [R=301,L]

I have not gotten any results from this change. Everything appears as they did before the change.

-Jacob

jdMorgan

7:10 pm on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following code for the indicated .htaccess file in each of the two domains should completely replace any and all code having to do with /hog_archive/index.php, /hog_archive/thumbnails.php, /hog_archive/displayimage.php, /razorback-photos/index-<number>.html, /razorback-photos/thumbnails-<number>.html, and /razorback-photos/displayimage-<number>-<number>.html
This code assumes that your PHP scripts remain in their original locations, i.e. the URLs have changed, while the filepaths have not.

In old-domain.com/.htaccess file:

 Options +FollowSymLinks
RewriteEngine on
#
#
# Externally redirect dynamic URL requests to corresponding static URL on new domain
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/index\.php\?cat=([0-9]+)
RewriteRule ^hog_archive/index\.php$ http://www.new-domain.com/razorback-photos/index-%1.htm[b]l?[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/thumbnails\.php\?album=([0-9]+)
RewriteRule ^hog_archive/thumbnails\.php$ http://www.new-domain.com/razorback-photos/thumbnails-%1.htm[b]l?[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/displayimage\.php\?album=([0-9]+)&pos=([0-9]+)
RewriteRule ^hog_archive/displayimage\.php$ http://www.new-domain.com/razorback-photos/displayimage-%1-%2.htm[b]l?[/b] [R=301,L]
#
#
# Externally redirect static URL requests to same URL on new-domain
#
RewriteRule ^razorback-photos/index-([0-9]+)\.html$ http://www.new-domain.com/razorback-photos/index-$1.html [R=301,L]
#
RewriteRule ^razorback-photos/thumbnails-([0-9]+)\.html$ http://www.new-domain.com/razorback-photos/thumbnails-$1.html [R=301,L]
#
RewriteRule ^razorback-photos/displayimage-([0-9]+-[0-9]+)\.html$ http://www.new-domain.com/razorback-photos/displayimage-$1.html [R=301,L]

In new-domain.com/.htaccess file:
 Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect dynamic URL requests to corresponding static URL
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/index\.php\?cat=([0-9]+)
RewriteRule ^hog_archive/index\.php$ http://www.new-domain.com/razorback-photos/index-%1.htm[b]l?[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/thumbnails\.php\?album=([0-9]+)
RewriteRule ^hog_archive/thumbnails\.php$ http://www.new-domain.com/razorback-photos/thumbnails-%1.htm[b]l?[/b] [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /hog_archive/displayimage\.php\?album=([0-9]+)&pos=([0-9]+)
RewriteRule ^hog_archive/displayimage\.php$ http://www.new-domain.com/razorback-photos/displayimage-%1-%2.htm[b]l?[/b] [R=301,L]
#
#
# Internally rewrite static URL requests to handler scripts
#
RewriteRule ^razorback-photos/index-([0-9]+)\.html$ /hog_archive/index\.php?cat=$1 [L]
#
RewriteRule ^razorback-photos/thumbnails-([0-9]+)\.html$ /hog_archive/thumbnails\.php?album=$1 [L]
#
RewriteRule ^razorback-photos/displayimage-([0-9]+)-([0-9]+)\.html$ /hog_archive/displayimage\.php?album=$1&pos=$2 [L]

Flush your browser cache completely (delete Temporary Internet Files) before testing any new code or changes.

I strongly suggest that you debug only one of these URL-types at a time, and do not confuse yourself (or us) by trying to fix all of it at once. Start with index.html on the new server, then do index.html on the old server, than when you get those working, go back and do thumbnails and displayimage.

The free "Live HTTP Headers" add-on for Mozilla/Firefox browsers is quite handy for "watching" external redirects.

The above may contain typos or errors of interpretation of your goals. It's the best I can do from here.

Jim

[edit] Corrections as noted below. [/edit]

[edited by: jdMorgan at 8:36 pm (utc) on Aug. 5, 2008]

londonhogfan

8:07 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



amazing work!

It works perfectly for what i was looking for.

I can't thank you enough.

londonhogfan

8:28 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



the only thing that isn't quite rite is when it takes me to the new site it still adds in the "?album=x" "?cat=x" and "album=x$pos=x" after the .html.

so the url looks like this.

newdomain.com/razorback-photos/thumbnails-71.html?album=71

when it just needs to be

newdomain.com/razorback-photos/thumbnails-71.html

Everything works though so probably not a big deal.

Thanks Again

jdMorgan

8:36 pm on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My error... As usual, I forgot to clear the query strings. See bolded corrections to substitution URLs in my post above.

Jim

londonhogfan

9:56 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



that did the trick. Thanks again!