【问题标题】:migrated system with new urls具有新网址的迁移系统
【发布时间】:2012-02-24 17:34:15
【问题描述】:

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

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

我现在需要重写网址,以便对喜欢的用户更友好

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 不是很好,我该怎么做才能让它变得更好?

【问题讨论】:

  • 您使用的是 apache? mod-rewrite 是否启用?
  • 是的,我想是的,我该如何检查?
  • 阅读此文,让我们知道:webune.com/forums/…

标签: .htaccess mod-rewrite lamp


【解决方案1】:

这是你需要使用的东西

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]

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

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

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

【讨论】:

    猜你喜欢
    • 2016-11-28
    • 2022-08-18
    • 2015-08-01
    • 2014-09-27
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    相关资源
    最近更新 更多