Solved

Rewrite slug

Posted on 2008-06-22
4
274 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

19 Experts available now in Live!

Get 1:1 Help Now