【问题标题】:PHP What is the best approach for a profile with sub pages?PHP 带有子页面的配置文件的最佳方法是什么?
【发布时间】:2019-11-25 00:39:09
【问题描述】:

我看到多个网站使用我所追求的类似 URL 方法。它看起来像这样。

https://example.com/users/84jdn59nmandbn4/profile 或者 https://example.com/users/84jdn59nmandbn4/achievements

随机 blob 是用户的唯一 ID 字符串。如果不使用随机字符串名称创建文件夹,如何在 PHP 中实现这一点?

【问题讨论】:

  • 通过 PHP,它不是。您可以使用 .htaccess 重定向来实现此目的。

标签: php


【解决方案1】:

原来的网址是这样的

https://example.com/users.php?id=84jdn59nmandbn4&profile

https://example.com/users.php?id=84jdn59nmandbn4&achievements

使用 Apache 的重写引擎,您可以创建搜索引擎友好 (SEF) 网址

示例:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?PID=$1&ID=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php?PID=$1 [L,QSA]

来源:mod_rewrite: Trailing slash on URL with two GET variables

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2017-06-20
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多