douchun5976 2012-07-10 16:54
浏览 13
已采纳

使用包含&文件夹而不是命名的php文件的index.php

Say I have a user database and don't want to use get to get the id (user.php?i=234) and want to use folders and index.php(s) instead (user/234)

I can do this by creating a new folder and index.php file in that folder when the user registers. I can put an include inside the index.php file (include '/users.php') and call a function that builds the page (buildUserPage(234);)

Is this the best way to do this?

How can I get the user id based on the parent folder if 234 is the user id?

How can I check if the url of the page is index.php so I can redirect to "../"?

  • 写回答

1条回答 默认 最新

  • dos3018 2012-07-10 21:31
    关注

    In the .htaccess file in the user directory, place the following:

    RewriteEngine On
    RewriteRule ^(\d+)/?$ ../users.php?i=$1 [QSA,L]
    

    For your question directory .htaccess file, try this:

    RewriteEngine On
    RewriteRule ^(\w+)?/?(\d+)?/?$ ../question.php?l=$1&i=$2 [QSA,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办