Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2004
    Posts
    8

    no .php or ? in a url

    How Do you make it so you can have an url without extensions and without having ? in the url. (ex: http://mysite.com/articles.php?id=23 -> http://mysite.com/articles/23) How do people do that?

  2. #2
    Join Date
    Dec 2001
    Location
    NYC, NY
    Posts
    798
    mod rewrite

  3. #3
    Join Date
    Jan 2004
    Posts
    8
    is this something that is on the server already? or would I need my host to add it?

  4. #4
    Join Date
    May 2004
    Location
    Omaha, NE
    Posts
    4

    Talking redirection ?

    Here is my guess.

    In the .htaccess file use redirection.

    edit the file and put a line like this in it

    Redirect /23 mysite.com/articles.php?id=23

    Hope that is what your looking for.

    Curt Curtis
    curt @webhostthis.com

  5. #5

    Re: no .php or ? in a url

    Originally posted by wews
    How Do you make it so you can have an url without extensions and without having ? in the url. (ex: http://mysite.com/articles.php?id=23 -> http://mysite.com/articles/23) How do people do that?
    Rename "articles.php" to "article". Add these lines to a file named ".htaccess" and place it in the same folder as article:

    Code:
    <files article> 
    ForceType application/x-httpd-php 
    </files>
    Now, in your "article" file, which will now be executed as if it had a .php extension, you can grab your "id" variable as follows:

    PHP Code:
    $page explode("/",$_SERVER['PATH_INFO']);
    $id $page[1]; 
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  6. #6
    Use mod_rewrite which is an extension to Apache.

    Something like this would go in your .htaccess file.

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} example.com
    RewriteRule ^/article/([0-9]+)$ /article.php?id=$1 [L]

    The last line is the key. The stuff on the left is what the request looks like, and on the right is what you want it replaced with. The $1 refers to the stuff in the parentheses on the left.

  7. #7
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994

    Re: Re: no .php or ? in a url

    Originally posted by Dan Grossman
    Rename "articles.php" to "article". Add these lines to a file named ".htaccess" and place it in the same folder as article:

    Code:
    <files article> 
    ForceType application/x-httpd-php 
    </files>
    Now, in your "article" file, which will now be executed as if it had a .php extension, you can grab your "id" variable as follows:

    PHP Code:
    $page explode("/",$_SERVER['PATH_INFO']);
    $id $page[1]; 
    I much prefer using this method than relying on mod_rewrite. I use it myself on a number of sites.

  8. #8
    I was looking for a solution to this recently and found this extremely useful article...

    http://www.zend.com/zend/spotlight/searchengine.php

  9. #9
    That's what I just taught ya how to do
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  10. #10

  11. #11
    But all your URLs will still have .php with the Zend method. My post covers that article and thensome in just a few lines
    Dan Grossman - dan @ awio.com
    My Blog | Affiliate Program for Web Hosts

  12. #12
    heh heh, OK Dan - take up your argument with the author of the article, I'm only the messenger!

    I might even adopt your method!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •