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
Solved

Rewrite slug

Posted on 2008-06-22
4
278 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Functions in phpMyAdmin 8 26
How to delete values from an array using php 4 22
Undefined variable problem 5 22
How do I show metrics with PHP or Javascript 6 31
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

840 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