mdedens Posted August 25, 2007 Posted August 25, 2007 Hi, I have a 301 redirect setup in an old domain's htaccess file, but my URLs with "?" "&" and "%20" don't seem to be redirecting. So I thought I would ask the experts and see if anyone knows how to redirect a dynamic URL with special characters on an old domain to a static URL on new domain. (*** added so no URLs are in post) So I would like this URL: http://***.oldomain.***/olddir/directory.php?CAT=100&catName=Widgets To go to this URL: http://***.newdomain.***/widgets.php > Example: Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC] redirect 301 /olddir/directory.php?CAT=100&catName=Widgets http://***.newdomain.***/widgets.php Thanks for any advice! Quote
TCH-Andy Posted August 25, 2007 Posted August 25, 2007 Try something like; >RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /olddir/directory\.php\?CAT=([^&]+)&catname([^\ ]+)\ HTTP/ RewriteRule ^index\.php$ http://***.newdomain.***/%2.php? [R=301,L] Quote
mdedens Posted August 25, 2007 Author Posted August 25, 2007 Hi Andy, Thanks for taking a crack at it. I tried the code, but still can't get it to work. The pages show up as normal. If this is going to be too complicated or time consuming to troubleshoot, is there an alternate method that could be used to redirect any URLs using that directory.php file. So any page that calls "directory.php" and no matter what comes after it, would redirect to one page on a new domain? like this URL: http://***.oldomain.***/olddir/directory.php?CAT=100&catName=Widgets would go to this URL: http://***.newdomain.***/directory.php'>http://***.newdomain.***/directory.php this URL: http://***.oldomain.***/olddir/directory.php?CAT=5654&catName=MoreWidgets would go to this URL: http://***.newdomain.***/directory.php Thanks again for your help! Quote
click Posted August 25, 2007 Posted August 25, 2007 I believe something like this should do what you want. >RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteRule ^olddir/directory\.php$ http://www.newdomain.com/directory.php [R=301,L] Quote
mdedens Posted August 25, 2007 Author Posted August 25, 2007 Hi Click I gave it a try but the old page still shows up normally. Both directory.php and any version with strings of characters after it show up fine. Also, I only put the code given here in the htaccess. Quote
TCH-Andy Posted August 25, 2007 Posted August 25, 2007 It sounds as if you have something else going on. Can you PM me the domain name ? Quote
mdedens Posted August 26, 2007 Author Posted August 26, 2007 Finally found what I needed... thanks again for all your help. It pointed me in the right direction >Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteCond %{REQUEST_URI} ^/olddir/ RewriteCond %{QUERY_STRING} CAT=100&catName=Widgets RewriteRule ^(.*)$ http://***.newdomain.***/widgets.php? [R=301,L] Quote
click Posted August 26, 2007 Posted August 26, 2007 I guess I misunderstood. I thought you were wanting to ignore the query string and redirect all requests to the new URL. Anyhow, I'm glad you figured it out. Quote
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.