Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

301 redirect from URL with query string to new domain with different query string

I am trying to figure out how to do a 301 redirect in my htaccess file to redirect some files to a new domain. Here's what I need to know how to do:

OLD URL: http://www.example.com/index.php?page=news&id=2366

NEW URL: http://www.example2.com/news.php?name=23546

The redirects don't have to be automatically created. I can hard-code the pages I need to redirect in the htaccess file, I just don't know the format to use as I've read that a "standard" 301 redirect won't work with query strings.

Basically this is what I want to do, but from my research so far it doesn't sound like it can be done this way.

redirect 301 /index.php?page=news&id=2366 http://www.example2.com/news.php?name=23546
like image 414
Sherwin Flight Avatar asked Apr 13 '12 05:04

Sherwin Flight


People also ask

Can you redirect a URL with a query string?

You can use URL Redirect to forward your visitors to a specific page at the destination URL and pass values via query strings to the destination.

How do I redirect a URL to another domain?

You changed your domain name and you want to redirect all requests to the new domain? You can create such a redirect by adding a few lines in the site's . htaccess file. To redirect with a 301 HTTP response ( Moved Permanently ), use R=[301,L] on the last line.

Which redirect should you use when you transition to a new domain?

301 Redirect - Unmasked It is considered to be the most efficient and search engine-friendly method for webpage redirection. 301 redirects are particularly useful under the following circumstances: - You've moved your site to a new domain, and you want to make the transition as seamless as possible.


1 Answers

You could use a rewrite rule with a query string match condition, such as:

RewriteEngine On
RewriteCond   %{REQUEST_URI}    ^/index.php$
RewriteCond   %{QUERY_STRING}   ^page=news&id=2366$
RewriteRule   ^(.*)$ http://www.example2.com/news.php?name=23546   [R=301,L]

Checkout this blog page for more information on how this works.

like image 94
Reggie Avatar answered Sep 29 '22 03:09

Reggie