dousha1831 2013-04-27 19:11
浏览 99
已采纳

查找路径名称以用作PHP自定义构建的cms的slug

I'm building a website with a custom content management system, and I want to build a slug area like wordpress. I want to retrieve the path name from my front-end depending on the page they're on, and echo that out in my backend in the slug area.

I'm using php and my front-end is dynamic, which means I have one page, and depending on what the user clicks on, I will include that file.

What I want the code to look like for the slug in the backend:

<?php
//front end path/ echo $slug;
?>

My front-end path looks something like this: blahblah/index.php/slug-name

I have a slug stored in the database that I will echo out, but my problem is I don't know how to retrieve the front end path and echo it out in the backend. I realize I can type the front-end path manually, but I think doing it dynamically would be better incase I move my website to a different location in the future.

I've tried using pathinfo or $_SERVER but that echos out my backend path rather than my front end.

Hopefully I was clear, if not, ask me to clarify something. Thanks again.

  • 写回答

2条回答 默认 最新

  • doushuo1989 2013-04-27 19:23
    关注

    You need the rewrite module for apache or nginx.

    That allows you to do like this:

    PrettyPath(This will be seen to all visitors): http://blah.com/blah/bl/ah/test

    => RealPath(This can be used for develop): http://blah.com/blah/index.php?slug=bl/ah/test

    You can do beautiful job like this for using rewrite module. (Rewrite Example)

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图