将带有 GET 参数的 URL 重写为 .pdf
Rewriting a URL with GET Parameters to .pdf
假设我在 WordPress 中有这样的动态 URL:
https://example.com/category/post-title/?format=pdf
https://example.com/category2/post-title2/?format=pdf
我希望将它们重写为:
https://example.com/category/post-title.pdf
https://example.com/category2/post-title2.pdf
如何使用 htaccess 执行此操作?
我尝试过类似的方法,但它不起作用:
#Options +FollowSymLinks
#RewriteEngine on
#RewriteRule ^.(.*) /?format=
你可以这样做:
RewriteEngine On
RewriteRule ^([^/]+)/(.+?)\.pdf$ //?format=pdf [L]
这将在内部将 /folder/foobar.pdf
的请求映射到 /folder/foobar?format=pdf
。请记住将此代码放在 htaccess 的顶部或 WordPress 重写规则之前。
假设我在 WordPress 中有这样的动态 URL:
https://example.com/category/post-title/?format=pdf
https://example.com/category2/post-title2/?format=pdf
我希望将它们重写为:
https://example.com/category/post-title.pdf
https://example.com/category2/post-title2.pdf
如何使用 htaccess 执行此操作?
我尝试过类似的方法,但它不起作用:
#Options +FollowSymLinks
#RewriteEngine on
#RewriteRule ^.(.*) /?format=
你可以这样做:
RewriteEngine On
RewriteRule ^([^/]+)/(.+?)\.pdf$ //?format=pdf [L]
这将在内部将 /folder/foobar.pdf
的请求映射到 /folder/foobar?format=pdf
。请记住将此代码放在 htaccess 的顶部或 WordPress 重写规则之前。