【问题标题】:Custom apache url-writing, with directory separator自定义 apache url-writing,带有目录分隔符
【发布时间】:2013-10-02 19:45:08
【问题描述】:

是否有任何简单/更快的方法来更改网址,例如

http://example.com/profile.php?id=52 

http://example.com/profile/52/username

如果我有来自数据库的$row['id']$row['username']

我试过了,

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^profile/(.*)$ /profile.php?id=$1 [QSA,L]

但是,number/username 部分似乎很混乱。

【问题讨论】:

    标签: php apache url-rewriting


    【解决方案1】:

    将规则更改为仅将数字分配给 $1:

    RewriteRule ^profile/([0-9]*)$ /profile.php?id=$1 [QSA,L]
    

    【讨论】:

    • 谢谢,但它似乎不起作用。我刚刚做了http://site.com/profile/52/username 并没有显示任何内容
    • 你(和我)在 ^ 之后错过了 /。但也许还有其他错误。也许在 mod_rewrite 中启用日志记录会很有用。
    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多