1

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?

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Croises Jul 05 '17 at 23:56

1 Answers1

1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84