使用新 url 迁移系统

发布于 2025-01-01 17:30:44 字数 439 浏览 3 评论 0原文

我正在将系统从 MVC 切换到自定义代码系统。目前我们正在使用这种格式的 url:

index.php?part=CAPACITOR&type=CERAMIC&model=0805&page=spec

我现在需要重写 url,以便对用户来说更加友好,例如

mysitecom/CAPACITOR/
mysitecom/CAPACITOR/CERAMIC/
mysitecom/CAPACITOR/CERAMIC/0805/spec.html#2

#1 和 #2 是在 jquery 中加载的页面。开发人员使用旧方法使用 /index.php/CAPACITOR/CERAMIC/0805/spec.html

因为我认为在 url 中使用 index.php 不好,我该怎么做才能使它更好?

I am switching system from a MVC to a custom code system. Currently we are using this format for urls:

index.php?part=CAPACITOR&type=CERAMIC&model=0805&page=spec

I need now to rewrite urls like to be more nice for user like

mysitecom/CAPACITOR/
mysitecom/CAPACITOR/CERAMIC/
mysitecom/CAPACITOR/CERAMIC/0805/spec.html#2

where #1 and #2 are the pages loaded in jquery. The developer use the old way using /index.php/CAPACITOR/CERAMIC/0805/spec.html

Because I don't think using the index.php in the url is good, what can I do to make this better?

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

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

发布评论

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

评论(1

生生不灭 2025-01-08 17:30:44

这是您需要使用的内容

RewriteEngine On
RewriteBase /

RewriteRule ^([a-z0-9\-_]+)/?$ index.php?part=$1&type=all&model=all&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=all&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=$3&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_\.]+)\.html$ index.php?part=$1&type=$2&model=$3&page=$4 [L,NC]

因此,当未提供文件夹(例如陶瓷)时,您可以添加一个标志来加载所有文件夹,模型的想法相同。这意味着如果仅提供第一部分,则仅使用第一条规则。默认情况下,从 page.html 开始,您可以加载索引。

现在,a-z0-9\-_ 仅表示任何字母、数字、破折号和下划线。如果您愿意,可以使用 ([^/]+),这样可以使用更多字符。

L 表示last,表示如果规则匹配,它将停止。 NC 表示非大小写,因此 A = a 或 ABC = abc。

Here's what you need to use

RewriteEngine On
RewriteBase /

RewriteRule ^([a-z0-9\-_]+)/?$ index.php?part=$1&type=all&model=all&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=all&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/?$ index.php?part=$1&type=$2&model=$3&page=index [L,NC]
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_\.]+)\.html$ index.php?part=$1&type=$2&model=$3&page=$4 [L,NC]

So when a folder (example CERAMIC) is not provided you can add a flag to load all, same idea for model. It means that if only the first part is provided only he first rule will be used. As of the page.html by default you can load the index.

Now, a-z0-9\-_ means any letters, numbers, dashes and underscore ONLY. You can use ([^/]+) if you prefer that will allow you to use more characters.

The L mean last meaning if the rule match, it will stop. NC means non case so A = a or ABC = abc.

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