How to change “attachment_id” in attachment permarlink?

I changed attachment permalink by add_filter('attachment_link','my_media_url');
from

http://domain.com/?attachment_id=123

to:

Read More
http://domain.com/?media=123

The change is successful. But, with the new URL, the page is not found. Some suggest rewrite rules like: this

'media/(.+)' => 'index.php?attachment=' . $wp_rewrite->preg_index(1)

I tried, it doesn’t work in my case. Instead of modify patterns before or after “attachment_id”, I want to replace “attatchment_id” with “media” and keep all the other stuffs unchanged.
Is this a question of rewrite, or should I study something else?
I tried this, not working either:

function attachment_rewrite( $wp_rewrite ) {
     $rule = array(
         '/?media=' => 'index.php?attachment_id=' . $wp_rewrite->preg_index(1)
     );

    $wp_rewrite->rules = $rule + $wp_rewrite->rules; } add_filter( 'generate_rewrite_rules', 'attachment_rewrite' );

Related posts

Leave a Reply