Jump to content
mdedens

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

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

It sounds as if you have something else going on. Can you PM me the domain name ?

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...