【发布时间】:2014-05-31 01:22:36
【问题描述】:
使用 URL 重写,我想这样:www.xxx.com/view-item/abc 到:www.xxx.com/item/abc.pdf。如何在 .htaccess 中使用重写规则?一直在查看http://httpd.apache.org/docs/current/rewrite/flags.html#flag_t 和其他网站,但无法弄清楚。
【问题讨论】:
标签: url-rewriting
使用 URL 重写,我想这样:www.xxx.com/view-item/abc 到:www.xxx.com/item/abc.pdf。如何在 .htaccess 中使用重写规则?一直在查看http://httpd.apache.org/docs/current/rewrite/flags.html#flag_t 和其他网站,但无法弄清楚。
【问题讨论】:
标签: url-rewriting
如果您希望在没有 HTTP 301 或 302 的情况下在内部进行重写,请尝试以下操作:
RewriteEngine on
RewriteRule ^/view-item/(.+) /item/$1.pdf [L]
如果 HTTP 301 或 302 重定向都可以,那么 Mod_rewrite 在这里有点过头了。你也可以使用 RedirectMatch:
RedirectMatch ^/view-item/(.+) /item/$1.pdf
【讨论】: