Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

to:

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' );
share|improve this question
    
Does this help? wordpress.stackexchange.com/a/14931/10691 –  its_me Jul 2 '12 at 4:01
    
No, that rule remove "?" and modify "_id" to "/id". I want to keep "?" and modify"attachment_id" to "media" –  Jenny Jul 2 '12 at 4:21
    
Hmm... I meant, modify that code to your needs. Can you try this and see if it works? pastebin.com/8715TTVi –  its_me Jul 2 '12 at 5:01
    
Thanks for the code! But it can't find the page either. –  Jenny Jul 2 '12 at 5:22
    
"Compilation failed: nothing to repeat at offset 1 in ....\wp-includes\class-wp.php on line 201" –  Jenny Jul 2 '12 at 5:31
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.