We have some proplem with seo and need rewrite pages with id from
example.com/media/player/related.php?mode=related&video_id=12345
to
example.com/video/12345
All id parameters have numerical values. RewriteEngine On
How can we achieve this?
We have some proplem with seo and need rewrite pages with id from
example.com/media/player/related.php?mode=related&video_id=12345
to
example.com/video/12345
All id parameters have numerical values. RewriteEngine On
How can we achieve this?
In order to redirect from /media/player/related.php?mode=related&video_id=12345
(containing a query string) to /video/12345
then you could do something like the following near the top of your .htaccess
file.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^mode=related&video_id=(\d+)
RewriteRule ^media/player/related.php$ /video/%1 [R=302,L]
This matches the source URL as mentioned in the example, except the value of the video_id
URL param is captured and assumed to be numeric only. This also just tests that the query string starts with the stated query string, so any additional URL params are ignored.
Change the 302
(temporary) status to 301
if this is intended to be a permanent redirect, but only after you have checked that it's working OK. (301s are cached hard by the browser so can make testing problematic.)
Presumably, you have existing directives or some kind of front controller that already rewrites /video/12345
back to the "real" URL? The check against the REDIRECT_STATUS
environment variable is to prevent a redirect loop, assuming this is the case.