Jump to content

Friendly URLs ??


nicholasstephan

Recommended Posts

So - The goal is pretty simple, but the application is proving harder than I thought it would be. I'd like to let people type in (and see) friendly looking URLs, but have them load dynamic content.

 

For example: instead of http://www.mysite.com/article.php?id=1234?uid=4321 (whatever), I'd like to see http://www.mysite.com/articles/ArticleTitle.

 

To do this, I'm thinking:

 

1) with .htaccess, I shunt Apache 404 errors to a page that uses Php's $_SERVER global to grab the url and split it up into variables.

 

2) I use those variables to run MySQL queries, read files, build and populate pages, etc...

 

3) and output the results. If the exact article is found, display it. If it's not, be able to say "did you mean... " and treat it like a search.

 

This seems to be all well and good, but then you try to click on something and you find that because you haven't redirected the user, all your relative links are relative to a non-existing directory!  :'( So href="about.php" goes to "whatever_the_user_typed/about.php"... not exactly a good situation, considering this just leads back to the 404 page and everything gets very confused.

 

I can put a redirect in there, so the user types /team/john and gets forwarded onto /team.php?id=123, but that kind of defeats the purpose as you want them to be able to look up and see something they might remember and tell others.

 

I've looked into redirecting, then using a apache mod_rewrite, but it seems stupid redirect (changing the url), then manually change it back again... :-\

 

Am I going about this entirely the wrong way. There must be a solution out there...

 

Anyone have any advice. I don't need someone to write the code for me, I can muddle through it, just some direction... maybe a couple of links...

 

 

 

Thanks

Link to comment
Share on other sites

to make this more friendly you'd probably want to do something like:

 

RewriteRule ^articles/(.*?)/.*$ article.php?id=$1

 

that will turn a url like:

 

http://www.mysite.com/articles/1234/COOL_WAY_TO_DO_STUFF

 

into

 

http://www.mysite.com/article.php?id=1234

 

transparently.. meaning that url will redirect you to the second url without ACTUALLY redirecting, just showing the content from the second url meanwhile keeping the first url, but this new url rewriting system MIGHT mess up certain things.. such as images and links. be wary :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.