问题
By default, I have an attachment page URL:
http://example.lt/photo/juokingi-pokalbiai-22-nuotraukos/attachment/221/
I want have:
http://example.lt/photo/juokingi-pokalbiai-22-nuotraukos/gallery/221/
or:
http://example.lt/photo/juokingi-pokalbiai-22-nuotraukos/221/
or:
http://example.lt/photo/juokingi-pokalbiai-22-nuotraukos/img_name
Is it possible to rewrite the attached images URL?
In permalinks settings, I cant set additional URL only for tags and category, how about attachments?
回答1:
Add this to your .htaccess
in your web root /
directory
RewriteEngine on
RewriteBase /
# for /photo/juokingi-pokalbiai-22-nuotraukos/gallery/221/
RewriteRule ^(.*)/gallery/(\d+)/?$ $1/attachment/$2 [NC,L]
# if "photo/juokingi-pokalbiai-22-nuotraukos" path is static followed by id
RewriteRule ^(photo/juokingi-pokalbiai-22-nuotraukos)/(\d+)/?$ $1/attachment/$2 [NC,L]
Unless, the image name also contains the attachment id; handling a URL like /photo/juokingi-pokalbiai-22-nuotraukos/img_name
would not be possible.
来源:https://stackoverflow.com/questions/19182947/wordpress-rewrite-post-gallery-image-url