Forum Moderators: phranque
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]
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]
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
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
Jim
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.
Do not change the RewriteCond pattern; Remember, it must match the request sent by the browser.
Jim
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]
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
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
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
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]
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]
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]
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