1

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.

4

2 回答 2

1

您需要 apache 或 nginx 的重写模块。

这使您可以这样做:

PrettyPath(所有访问者都可以看到):http ://blah.com/blah/bl/ah/test

=> RealPath(可用于开发):http ://blah.com/blah/index.php?slug=bl/ah/test

您可以使用 rewrite 模块做这样的漂亮工作。(重写示例

于 2013-04-27T19:23:28.203 回答
0
$front_end_path = 'your/site/path';
$full_url = $front_end_path . $slug;
于 2013-04-27T19:18:17.570 回答