首页 文章

php到html .htaccess帮助

提问于
浏览
0

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

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

RewriteEngine on RewriteRule ^([^/ .]) . html index.php?p = $ 1 [L] index.php?p = about_us
RewriteRule ^([^/]) . html index.php?p = order&course_id = $ 1 [L]

index.php?p=order&course_id=5

谢谢,

2 回答

  • 0

    你能给出与模式块匹配的示例url以及你希望它们被重写的内容吗?这将非常有帮助 .

    我注意到的一件事是你测试的第一个正则表达式,如果你将模式块与 + 匹配,这意味着1次或更多次,而第二个你用 * 检查它,这意味着0或更多,所以我不认为第二个永远都会被召唤,虽然我对regexp很新,但这只是我注意到的事情 .

    这对我来说是非常有用的资源:

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

    http://forum.modrewrite.com/

  • 0

    从您将使用的网址示例,这应该工作:

    # 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]
    

    取决于您的页面结构 .

相关问题