dongtuoleng8624 2012-05-26 22:19
浏览 25
已采纳

重写php网址的规则

I've tried to find an answer for a question i had in my mind, but it seems to I can't find it.

How is it possible to make some php urls with "?" and "=" to /

Example one (1):

example.com/user.php?profile=example

to:

example.com/user/profile/example

Example two (2):

example.com/forum.php?thread=example-in-an-example

to:

example.com/forum/thread/example-in-an-example

Like a code that takes the second "/" (slash) as a "?" and the third and the rest as a "=" so i can freely use it instead of making a new one for each page...

LIKE: /forum (or any others) is like the page itself AND: /thread (or any others) is like the $_GET AND: /example-in-an-example (or any others) is like the value to the $_GET

EXTRA: here is a code from Jeroen:

RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?$2=$3 [L]

Problem one (1): when going to like: "example.com/forum" or "example.com/user" its giving a 404 error Problem two (2): When using links like "example.com/forum/thread/test-thread/reply/2" it gives 404 error, (supose to loop with "&" and "=" after making the 1st real one so its enable to use more than one $_GET)

  • 写回答

2条回答 默认 最新

  • doulongsha5478 2012-05-26 22:23
    关注

    Add this to your .htaccess file:

    RewriteEngine On
    RewriteRule ^user/profile/(.*)/$ user.php?profile=$1 [L]
    RewriteRule ^forum/thread/(.*)/$ /forum.php?thread=$1 [L]
    

    Or a more generic version...

    RewriteEngine On
    RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?$2=$3 [L]
    

    Make sure Apache's mod rewrite is enabled!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?