Solved

Rewrite slug

Posted on 2008-06-22
4
275 Views
Last Modified: 2010-03-04
I tried to do this once before and never found a solution that worked so I'm giving it another shot. I know the rewrite rule to rewrite my pages but I'm curious if something like this can be done.

I want to use slugs (keyword) so I can do the following:
www.site.com/keyword

Where keyword would point to:
www.site.com/profiles?lookup=keyword (profile id)

BUT, I would also like to rewrite my other pages as well
www.site.com/whateverpage/

Would actually be
www.site.com/whateverpage.php

Can anyone lend a hand here please?
0
Comment
Question by:SOakley54
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 500 total points
ID: 21843487
You might consider rewrite all requests to some kind of dispatcher, and then from there you can determine if the keyword is a "reserved" keyword, eg one of your pages such as /contacts or /whateverpage, if not then you can redirect to /profiles?lookup=keyword..

Does that make sense?
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 21843507
You might make a dispatcher that does something like this:

<?php
switch(strtolower($_SERVER['REQUEST_URI']))
{
      case '/':
            require_once 'home.php';
            break;
      case '/contact':
            require_once 'contact.php';
            break;
      case '/aboutus':
            require_once 'aboutus.php';
            break;
      default:
            require_once 'profiles.php'; /* run the profiles script to determine which profile it is */      
}
?>
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 21843556
Okay, so this might work, try this rewrite rule:

RewriteRule ^(.+)/?$      dispatcher.php?path=$1       [L]


Now, our dispatcher.php:

<?php
switch(strtolower($_GET['path']))
{
      case '/':
            require_once 'home.php';
            break;
      case '/contact':
            require_once 'contact.php';
            break;
      case '/aboutus':
            require_once 'aboutus.php';
            break;
      default:
            require_once 'profiles.php'; /* run the profiles script to determine which profile it is */      
}
?>



Now our profiles.php:

<?php
 echo "You're looking for the profile at: {$_GET['path']}";
?>




This is just an idea...I'm eager to what other people think about this.
0
 

Author Comment

by:SOakley54
ID: 21849907
Once I modified my Google search to "URL Routing" I came up with a few better hits. Ideally it would be great to just port all my work over to something like ZF or Cake and use their well written MVC architecture instead of writing my own (non-MVC) but it's just not in the cards at this time.

All of my development on this project is at home so I can't post up what I have so far. To be honest I can't say I truly care for the approach I'm investing in either. To me it's like a really half-assed version of MVC except just the C part; sigh. The good news is that it is routing properly. The bad news is that I have to hold all of my url calls inside of a switch() statement which is quite time consuming to port over right now. Especially because all of my pages have to be self-contained inside of a function with alternate switches to get the parameters.

Like I said, I'll throw the code up when I get home and get some more eyes on this. It would be interesting to see what I get back and thank you for taking the time out as well. It's very much appreciated :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now