RewriteRule 重命名 URL?

发布于 2024-09-19 02:35:13 字数 639 浏览 3 评论 0原文

我有两个关于 RewriteRule 的问题,但它们都是密切相关的,所以我希望我可以在一篇文章中问它们。

第一个是我想从任何 URL 的末尾删除尾随 index.html,例如:

http://www.example.com/index.html -> http://www.example.com/

第二个是显示 URL http://www.example。对于以下所有 URL,浏览器地址栏中的 com/contact/

http://www.example.com/contact/
http://www.example.com/contact/index.html
http://www.example.com/contact/success.html
http://www.example.com/contact/failure.html

例如,如果用户被重定向到 http://www.example.com/contact/success.html > 我希望向他们显示该页面,但使用 http://www.example.com/contact/ 作为 URL。这可能吗?

I have two questions regarding RewriteRule, but they're both closely related so I hope it's OK I ask them both in a single post.

The first is that I'd like to strip trailing index.html's from the end of any URL, e.g.:

http://www.example.com/index.html -> http://www.example.com/

The second is to display the URL http://www.example.com/contact/ in the browser's address bar for all of the following URLs:

http://www.example.com/contact/
http://www.example.com/contact/index.html
http://www.example.com/contact/success.html
http://www.example.com/contact/failure.html

For example, if the user is redirected to http://www.example.com/contact/success.html I'd like that page to be displayed to them, but with http://www.example.com/contact/ as the URL. Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戴着白色围巾的女孩 2024-09-26 02:35:13

对于索引:

RewriteRule ^(.*)/index.html /$1/ [R]

第二:

RewriteRule ^contact/(success|failure)\.html /contact/ [L]

For the index:

RewriteRule ^(.*)/index.html /$1/ [R]

Second:

RewriteRule ^contact/(success|failure)\.html /contact/ [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文