How can I write a .htaccess redirect to find all numbers?

I'm trying to figure out a regular expression that will find some numbers in a URL and use them in the URL I redirect to.

Redirect 301 /page.php?id=95485666 http://test.com/profile/info/id/95485666

i was thinking maybe

Redirect 301 /page.php?id=([0-9]+) http://test.com/profile/info/id/$1

but it doesn't seem to work

Also, if I do a 301 redirect, how long do i have to keep the code in the .htaccess file? when is Google gonna figure out that the new link is the good one?

Answers


You can't match against the query string in the Redirect directive (nor in a RedirectMatch/RewriteRule either). You need to use mod_rewrite's %{QUERY_STRING} var:

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=([0-9]+)($|&)
RewriteRule ^/?page\.php$ http://test.com/profile/info/id/%2? [L,R=301]

Need Your Help

Get checkbox value into a div like content

jquery text checkbox value

I found this code here... Instead of displaying the values on an alert, how to show them on a div like text content?

How to use StopWatch multiple times in C#?

c# optimization time

I have short code that performs different operations and I want to measure the time that takes to perform each. I read here about Stopwatch class, and wanted to optimize my time measurements.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.