breckenridgej Posted March 15, 2006 Share Posted March 15, 2006 I've been googling for hours to no avail. I'm trying to redirect a series of dynamic URLs that are all unique to more static URLs as I complete a port to Movable Type. The mapping looks like this: (OLD) http://www.nomadicplanet.com/ImageDetails....&CurrentImage=3 (NEW) http://www.jordansphotos.com/archives/byEn..._sur_sunset.php After all my searching, I haven't been able to figure out how to put the dynamic URL with the question mark on the left side of a .htaccess redirect. Attempt #1: Redirect 301 /ImageDetails\.aspx\?GalleryId=53&CurrentImage=3 http://www.jordansphotos.com/archives/byEn..._sur_sunset.php Nor, have I been able to create a RewriteRule that takes the dynamic URL and maps it to the appropriate static URL. Attempt #2: RewriteEngine On RewriteBase / RewriteRule ^ImageDetails\.aspx\?GalleryId\=53\&CurrentImage\=3$ archives/byEntry/galleries/destinations/usa/central_california_coast/20040124_big_sur_sunset.php [R=301,L] The other question I have is that I have about 1100 of these. And, given they are all different, is this going to be a performance problem? I was trying to avoid search engine penalties by not losing the URLs but if its going to be too difficult I could also just redirect the ImageDetails.aspx file back to the Index or something. Would appreciate any suggestions! Jordan Breckenridge Quote Link to comment Share on other sites More sharing options...
TCH-Tim Posted March 15, 2006 Share Posted March 15, 2006 (edited) Welcome to the forums Jordan. What are you porting to MT from? Edited March 15, 2006 by timhodge Quote Link to comment Share on other sites More sharing options...
breckenridgej Posted March 15, 2006 Author Share Posted March 15, 2006 Welcome to the forums Jordan. What are you porting to MT from? It is a custom .Net application. I can use my migration scripts to create a detailed entry-level mapping of old name to new name, but you can ascertain the new names from the old URL. Jordan Quote Link to comment Share on other sites More sharing options...
abinidi Posted March 15, 2006 Share Posted March 15, 2006 I can't help with the answer to your question. It's WAY above my head. But I thought I'd bid you welcome to the forums!! I'm sure somebody will be along that can give you some advice. Quote Link to comment Share on other sites More sharing options...
click Posted March 15, 2006 Share Posted March 15, 2006 Everything after the "?" is stripped from the url and placed in the QUERY_STRING variable so you would need to test against that. Maybe something like: RewriteCond %{QUERY_STRING} ^GalleryId\=53\&CurrentImage\=3$ RewriteRule ^ImageDetails\.aspx$ archives/byEntry/galleries/destinations/usa/central_california_coast/20040124_big_sur_sunset.php [R=301,L] 1100 RewriteRules in your .htaccess certainly wouldn't be pretty though! You could maybe send all references to "ImageDetails.aspx" to a php script that could manage the redirects a bit more gracefully. Quote Link to comment Share on other sites More sharing options...
TCH-Thomas Posted March 15, 2006 Share Posted March 15, 2006 Welcome to the forum, breckenridgej. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 15, 2006 Share Posted March 15, 2006 Welcome to the forum, breckenridgej Quote Link to comment Share on other sites More sharing options...
TCH-Rob Posted March 15, 2006 Share Posted March 15, 2006 Welcome to the forums Jordan. Quote Link to comment Share on other sites More sharing options...
breckenridgej Posted March 15, 2006 Author Share Posted March 15, 2006 Everything after the "?" is stripped from the url and placed in the QUERY_STRING variable so you would need to test against that. Maybe something like: RewriteCond %{QUERY_STRING} ^GalleryId\=53\&CurrentImage\=3$ RewriteRule ^ImageDetails\.aspx$ archives/byEntry/galleries/destinations/usa/central_california_coast/20040124_big_sur_sunset.php [R=301,L] 1100 RewriteRules in your .htaccess certainly wouldn't be pretty though! You could maybe send all references to "ImageDetails.aspx" to a php script that could manage the redirects a bit more gracefully. Is there a special syntax for invoking the PHP script from with htaccess? Quote Link to comment Share on other sites More sharing options...
click Posted March 15, 2006 Share Posted March 15, 2006 I would just use a RewriteRule to redirect to it. >RewriteRule ^ImageDetails\.aspx$ redirect_script.php [QSA] The QSA flag tells apache to re-append the QUERY_STRING to the redirected address. This would make the query string available to the php script in $_GET['GalleryId'], $_GET['CurrentImage'], etc. The script would then lookup the new location and redirect. I think the php to do a 301 redirect is: >header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.newdomain.com/newdir/newpage.htm"); Steven Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted March 15, 2006 Share Posted March 15, 2006 Welcome to the forums Jordan Quote Link to comment Share on other sites More sharing options...
TCH-JimE Posted March 16, 2006 Share Posted March 16, 2006 Welcome to the forums Jordan! JimE Quote Link to comment Share on other sites More sharing options...
breckenridgej Posted March 16, 2006 Author Share Posted March 16, 2006 (edited) Thanks for all the tips. For posterity, this is what I did to get it to work: .htaccess: >RewriteEngine On RewriteBase / RewriteRule ^redirecturl1\.aspx$ redirect_script.php [QSA] RewriteRule ^redirecturl2\.aspx$ redirect_script.php [QSA] RewriteRule ^redirecturl3\.aspx$ redirect_script.php [QSA] redirect_script.php: ><?php $id= ( isset( $_GET['ID'] ) ) ? $_GET['ID']: ''; $site_url = 'http://www.xxxxxxxxx.com/'; $url_redirects = array( '1' => 'archives/URL1', '2' => 'archives/URL2', '6' => 'archives/URL3', '7' => 'archives/URL4', ); if ( $id== '' ) { Header ("HTTP/1.1 301 Moved Permanently"); Header('Location: '.$site_url.'index.php'); } else { $url = $site_url.$url_redirects[$id]; Header ("HTTP/1.1 301 Moved Permanently"); Header('Location: '.$url); } ?> Edited March 16, 2006 by breckenridgej Quote Link to comment Share on other sites More sharing options...
TCH-Rob Posted March 16, 2006 Share Posted March 16, 2006 Glad to see you have it working. Quote Link to comment Share on other sites More sharing options...
breckenridgej Posted March 18, 2006 Author Share Posted March 18, 2006 I just discovered a problem with my solution (and in fact, with my entire .htaccess). URLs that do not match exactly on case are being directed to my 404 page. This includes my redirects for the URLs with query parameters and my static URLs. For example: http://www.somepage.com/page1.php?id=5323 is different than http://www.somepage.com/page1.php?ID=5323 This is particularly problematic because Google has indexed both versions of the URL. Is there an easy way to convert the URLs to all lower case before applying my other redirection rules including my PHP script? Thanks again. Jordan Quote Link to comment Share on other sites More sharing options...
click Posted March 18, 2006 Share Posted March 18, 2006 That should be easy enough to fix. For the .htaccess stuff, use the NC flag to make the Rewrite Rules case insensitive. RewriteRule ^redirecturl1\.aspx$ redirect_script.php [NC,QSA] On the PHP side, I think you should be able to use something like array_change_key_case(). Follow the link for more info. -Steven Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.