mod_rewrite 带或不带斜杠的 URL 重写

发布于 2024-09-14 00:02:52 字数 280 浏览 2 评论 0原文

写出 .htacess 以便 www.domain.com/about_us 和 www.domain.com/about_us/ 都转到 www.domain.com/about_us.php 的正确方法是什么

目前,我所拥有的是以下内容只是想知道是否有办法将其放在一行中

选项+FollowSymLinks
RewriteEngine 开启
RewriteRule ^(about)$ /about_us.php
RewriteRule ^(about/)$ /about_us.php

What is the correct way to write out the .htacess so that both www.domain.com/about_us and www.domain.com/about_us/ goes to www.domain.com/about_us.php

Currently, what I have is the below and just wonder if there's a way to put it in one line

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(about)$ /about_us.php
RewriteRule ^(about/)$ /about_us.php

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

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

发布评论

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

评论(2

迟到的我 2024-09-21 00:02:52

这是一个正则表达式,所以添加 ? / 之后将使 / 可选(出现 0 或 1 次)。另外,括号是不必要的:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^about/?$ /about_us.php

It's a regular expression, so adding ? after the / will make the / optional (0 or 1 occurrences). Also, the parenthesis are unnecessary:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^about/?$ /about_us.php
眼泪淡了忧伤 2024-09-21 00:02:52
RewriteRule ^about/?$ /about_us.php
RewriteRule ^about/?$ /about_us.php
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文