301 Redirect Url With A "?" In It To A New Domain?

liunx

Guest
Hi,<br /><br />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.<br /><br />(*** added so no URLs are in post)<br /><br />So I would like this URL:<br />http://***.oldomain.***/olddir/directory.php?CAT=100&catName=Widgets<br />To go to this URL:<br />http://***.newdomain.***/widgets.php<br /><br /><br /><div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><br />Example:<br /><br />Options +FollowSymLinks<br />RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC]<br /><br />redirect 301 /olddir/directory.php?CAT=100&catName=Widgets <!-- m --><a class="postlink" href="http://***.newdomain.***/widgets.php">http://***.newdomain.***/widgets.php</a><!-- m --><br /><br /></div><br /><br />Thanks for any advice!<!--content-->
<br />Try something like; <br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine on<br />RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /olddir/directory\.php\?CAT=([^&]+)&catname([^\ ]+)\ HTTP/<br />RewriteRule ^index\.php$ http://***.newdomain.***/%2.php? [R=301,L]<!--c2--></div><!--ec2--><!--content-->
Hi Andy,<br /><br />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.<br /><br />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.<br /><br />So any page that calls "directory.php" and no matter what comes after it, would redirect to one page on a new domain?<br /><br />like this URL:<br />http://***.oldomain.***/olddir/directory.php?CAT=100&catName=Widgets<br />would go to this URL:<br />http://***.newdomain.***/directory.php<br /><br />this URL:<br />http://***.oldomain.***/olddir/directory.php?CAT=5654&catName=MoreWidgets<br />would go to this URL:<br />http://***.newdomain.***/directory.php<br /><br /><br />Thanks again for your help!<!--content-->
I believe something like this should do what you want.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RewriteEngine On<br />RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]<br />RewriteRule ^olddir/directory\.php$ http://www.newdomain.com/directory.php [R=301,L]<!--c2--></div><!--ec2--><!--content-->
Hi Click<br /><br />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.<br /><br />Also, I only put the code given here in the htaccess.<!--content-->
It sounds as if you have something else going on. Can you PM me the domain name ? <br /><!--content-->
Finally found what I needed... thanks again for all your help. It pointed me in the right direction<br /><br /><div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>Options +FollowSymLinks<br />RewriteEngine on<br />RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]<br />RewriteCond %{REQUEST_URI} ^/olddir/<br />RewriteCond %{QUERY_STRING} CAT=100&catName=Widgets<br />RewriteRule ^(.*)$ <!-- m --><a class="postlink" href="http://***.newdomain.***/widgets.php">http://***.newdomain.***/widgets.php</a><!-- m -->? [R=301,L]</div><!--content-->
I guess I misunderstood. I thought you were wanting to ignore the query string and redirect all requests to the new URL.<br /><br />Anyhow, I'm glad you figured it out.<!--content-->
 
Top