+ Reply to Thread
Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By wjh2303
  • 1 Post By ramsankar

Thread: Cleaning dirty URLs

  1. #1
    wjh2303 is offline x10 Sophmore wjh2303 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    139

    Cleaning dirty URLs

    I was going to go for programming help, but since a search hadnt come up with anything i thought i'd ask this in tutorials and be optimistic that a reply would be worthy of such a description.

    Currently, some of the URLs around my site are what i believe is described as 'dirty', i.e they look like:
    and i would like to clean them up to look like
    or, since the id is sufficient to uniquely identify some piece of content, and therefore which filename.php would be calling it, perhaps even
    I've made a few queries on google and found references to mod_rewrite apache file, ASP, and pre-generating the page since it is dynamically generated but static in content (building the page from an SQL query which isnt going to change for a given query. However i am unfamiliar with fiddleing with apache, or ASP and cant readiy find anything that will get me started on how to do this.

    TIA
    dinomirt96 likes this.

  2. #2
    misson is offline Community Advocate misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,391

    Re: Cleaning dirty URLs

    Quote Originally Posted by wjh2303 View Post
    i thought i'd ask this in tutorials and be optimistic that a reply would be worthy of such a description.
    Read the forum rules. This forum isn't for asking for help, even asking for a tutorial.

    Quote Originally Posted by wjh2303 View Post
    I've made a few queries on google and found references to mod_rewrite apache file,
    Read the references. A mod_rewrite tutorial will tell you what you want to know.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Cleaning dirty URLs

    You don't need to use mod_rewrite.
    If you want to create the format like http://domain.com/filename/id then do this:
    Create a PHP file called 'filename' without the .php extension. This will receive the request
    Next, open the .htaccess file and insert this line:
    Code:
    <FilesMatch filename>
        ForceType application/x-httpd-php5
    </FilesMatch>
    This forces Apache to execute any requests for filename as PHP rather than look for the directory.
    Finally, in your 'filename' file add the following code and modify it to do the correct thing with the received id:
    PHP Code:
    <?php
    //get URL requested
    $expl explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
    //Find ID in URL
    $id intval($expl[count($expl)-1]);
    //Check ID found, otherwise redirect to homepage
    if(!$id){
    header("location: /");
    die();
    }

    //Do something with $id, probably not redirect like this though
    header("location: /filename.php?id=" $id);
    ?>

  4. #4
    Hoobrum's Avatar
    Hoobrum is offline x10Hosting Member Hoobrum is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    55

    Re: Cleaning dirty URLs

    Wow that looks like awesome code lemon-tree...I've gotta try that out sometime.

  5. #5
    ramsankar's Avatar
    ramsankar is offline x10Hosting Member ramsankar is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    India
    Posts
    37

    Re: Cleaning dirty URLs

    Cool info...
    karimirt47 likes this.

+ Reply to Thread

Similar Threads

  1. extensionless URLs for feeds?
    By andrewmoquin in forum Graphics & Webdesign
    Replies: 0
    Last Post: 08-05-2009, 04:45 AM
  2. Extentionless URLs
    By garrensilverwing in forum Programming Help
    Replies: 16
    Last Post: 05-05-2009, 12:58 PM
  3. image urls in sql
    By maxyes in forum Programming Help
    Replies: 1
    Last Post: 08-28-2008, 02:16 PM
  4. MediaWiki short urls
    By cowctcat in forum Free Hosting
    Replies: 2
    Last Post: 02-23-2008, 12:39 PM
  5. Something killed my clean URLs
    By nsm_nikhil in forum Free Hosting
    Replies: 4
    Last Post: 02-09-2008, 08:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers