【问题标题】:php to html .htaccess Helpphp 到 html .htaccess 帮助
【发布时间】:2011-06-16 16:16:22
【问题描述】:

我的 .htaccess 文件中有以下代码,顶部的 Rewrite 工作正常,bottem 不知道为什么,但我不知道如何修复它。

它看到 RewriteRule ^([^/]*).html index.php?p=order&course_id=$1 [L] 作为最高的重写命令,因为高亮部分,我不想放在一个目录里

重写引擎开启

重写规则 ^([^/.]+).html index.php?p=$1 [L]

index.php?p=about_us

重写规则 ^([^/]+).html index.php?p=order&course_id=$1 [L]

 index.php?p=order&course_id=5  

谢谢,

【问题讨论】:

  • 不确定我是否正确,因为您的两条规则的 LHS 条件相同 ^([^/]+).html ?

标签: .htaccess


【解决方案1】:

您能否给出应该与模式块匹配的示例 url,以及您希望将它们重写为什么?那会很有帮助。

我注意到的一件事是,您测试的第一个正则表达式是否将模式块与 + 匹配,这意味着 1 次或多次,第二个您使用 * 进行检查,这意味着 0 或更多,所以我不要认为第二个会被调用,虽然我对正则表达式很陌生,但这只是我注意到的。

这些资源对我很有帮助:

http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php

http://forum.modrewrite.com/

【讨论】:

  • @Gully 好的,所以你希望 domain.com/about_us 变成 domain.com/index.php?p=about_us 我想,但是第二个呢?
【解决方案2】:

从您将使用的网址示例中,这应该可以:

# http://website.com/about_us/ rewrites to /index.php?p=about_us
RewriteRule ^([0-9a-z_-]+)/?$ index.php?p=$1 [NC,L]

# http://website.com/order/12/ rewrites to /index.php?p=order&course_id=12
RewriteRule ^order/([0-9]+)/?$ index.php?p=order&course_id=$1 [NC,L]

第二次重写可能是:

# http://website.com/order/12/ rewrites to /index.php?p=order&course_id=12
RewriteRule ^([0-9a-z_-]+)/([0-9]+)/?$ index.php?p=$1&course_id=$2 [NC,L]

取决于您的页面结构。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 2010-10-29
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多