【发布时间】:2017-09-26 17:58:19
【问题描述】:
我有一个网站,我想替换 URL 的一部分,https://example.com/[THISPART]/file.ext。
将在现场请求的示例 URL:
https://example.com/example-page/sw.js
https://example.com/example-page/image.jpg
https://example.com/some-other-page/sw.js
https://example.com/some-other-page/file.pdf
https://example.com/page-with-attitude-4/sw.js
https://example.com/page-with-attitude-4/info.txt
我想如何重写它们:
https://example.com/content/example-page/sw.js
https://example.com/example-page/image.jpg
https://example.com/content/some-other-page/sw.js
https://example.com/some-other-page/file.pdf
https://example.com/content/page-with-attitude-4/sw.js
https://example.com/page-with-attitude-4/info.txt
也就是说,如果只请求 sw.js,则重写为其他 URL。 到目前为止,我在 htaccess 中使用的是这样的:
RewriteRule ^(.*)\/sw.js$ content/$1/sw.js [L]
我一直用http://htaccess.mwl.be/作为测试器,测试显示还可以,但是在现场使用时,它不起作用。有什么帮助吗?
【问题讨论】:
标签: .htaccess url mod-rewrite