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.

tickerll
  • 43
  • 1
  • 3
  • 10

2 Answers2

1

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)

Community
  • 1
  • 1
kargnas
  • 332
  • 3
  • 10
  • Hey kargnas, thanks for your answer. This is way beyond my level, and the website you provided is suitable for Korean speakers even after translating it. Perhaps I will google about this? – tickerll Apr 27 '13 at 19:29
  • NOT about rewriting the module. The module name is 'Rewrite Module'. Just see the code in example site. You can search 'rewrite', 'whole', 'index.php' and example code in example site ... from google. Or see this: http://stackoverflow.com/questions/8609735/excluding-files-from-htaccess-rewrite-rules – kargnas Apr 27 '13 at 19:37
  • See also: http://code-splash.com/2013/03/05/htaccess-url-rewriting-tips/ ... If you hosted from webhosting service, you can request the rewrite to server administrator. But I think, maybe that module is already enabled. And, '.htaccess' file can be used in hostingusers level. Many blog/bbs solutions written in php are using this skill. – kargnas Apr 27 '13 at 19:41
  • Wow, that's neat. Thanks, again. I will read up on it and try it out :) – tickerll Apr 27 '13 at 19:59
0
$front_end_path = 'your/site/path';
$full_url = $front_end_path . $slug;
member8888
  • 65
  • 7
  • Thanks for your reply, member8888; however, this returns the path to my backend and not my frontend path? – tickerll Apr 27 '13 at 19:21
  • Just reread your question. Why not just make the front end path a variable? Then if you have to move the site you just have to change that one variable. – member8888 Apr 27 '13 at 19:23
  • That's a good solution, I will do this if I can't figure out how to do it dynamically, although kargnas mentioned rewriting the module for apache.. – tickerll Apr 27 '13 at 19:30