Theres a way to convert links like:
http://www.localhost.lh/?attachment_id=41
into:
http://www.localhost.lh/attachment/id
or:
http://www.localhost.lh/author/attachment/id
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
here a simple WordPress rewrite rule to get the job done:
add_action('generate_rewrite_rules', 'attachment_rewrite_rule_14924');
function attachment_rewrite_rule_14924($wp_rewrite){
$new_rules = array();
$new_rules['attachment/(d*)$'] = 'index.php?attachment_id=$matches[1]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
just add this code to your theme’s functions.php file and save.
*note: the index.php is regardless of your existing URL structure.
Method 2
José Pablo
In addition to changing the permalinks settings in your dashboard to make pretty URL’s, you can create a folder named “attachments” in the root of your site to hold the files that you would like site visitors to download. In addition to uploading the files you wish to share, you should create (using notepad or any text editor) a blank file named index.html and upload it to the “attachments” directory. Adding the blank file will prevent people from browsing the directory and downloading all of the files unless you provide them with the specific URL.
Saludos
Method 3
You could use a plugin like PrettyLink to create a friendly URL to redirect to the attachment. http://wordpress.org/extend/plugins/pretty-link/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0