我使用的是标准的WordPress图库,但我对图像的url(链接到附件页)不满意。
在我目前的情况下,库url为:
http://example.com/gallery/
图像url为
http://example.com/image01/
我试图实现的是,库url将保持不变,但图像(附件)url将是:
http://example.com/gallery/image01/
我可以自定义我的图库代码,将图库段塞添加到附件url(可能通过创建自定义短代码来获取图库短代码的内容,并只替换url),但我无法创建。htaccess文件工作(如果有比使用.htaccess文件更好的方法,我不介意)。
我的当前。htaccess代码为
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /main/dmm/wp01/
# beginning of my code
RewriteRule ^selected-work/(.*)/ $1/
# end of my code
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /main/dmm/wp01/index.php [L]
</IfModule>
# END WordPress
# Caching disabled
<filesMatch "\\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
# END OF Caching disabled
SO网友:Juraj.Lorinc
所以我能够使用WordPress重写API使其工作(没有Tom sugested的.htaccess)。以下是我的工作代码(来自functions.php):
function add_rewrite_rules( $wp_rewrite )
{
$new_rules = array
(
\'(the-gallery-slug)\\/(.?.+?)(?:/([0-9]+))?/?$\' => \'index.php?pagename=$matches[2]\'
);
// Always add your rules to the top, to make sure your rules have priority
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action(\'generate_rewrite_rules\', \'add_rewrite_rules\');
以下是对我帮助很大的链接:
"Wordpress - wp_rewrite rules" post on stackoverflow
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)