Solved

Rewrite slug

Posted on 2008-06-22
4
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 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