1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Making a query look like a directory

Discussion in 'PHP' started by tarponkeith, Sep 18, 2008.

  1. #1
    I've got a question, and am not sure how in-depth this is...

    A buddy of mine told me there's a way to make a script that accepts input and looks like a directory structure...

    For example:

    /something/input1/
    /something/input2/

    Where input1 and input2 are not actual directories, but data being passed to /something/index.php

    I know you can pull this off with mod-rewrite, but am just wondering if it's also possible with PHP...

    Thanks
     
    tarponkeith, Sep 18, 2008 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    I see what you mean, you need to specify the parameters in a .htaccess file. But php alone can't do it, because server doesn't know that the link is symbolic.
     
    Kaizoku, Sep 18, 2008 IP
    tarponkeith likes this.
  3. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    You can actually create the directory with php, but MOD rewrite works good for this. :)
     
    JEET, Sep 18, 2008 IP
    tarponkeith likes this.
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    it is possible - you can set via mod_rewrite to redirect any request that's not a filename to index.php
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    Code (markup):
    you can then query $_SERVER['DOCUMENT_URI'] or whatever to grab the address they typed and compare it against what you need...

    hth
     
    dimitar christoff, Sep 19, 2008 IP
    tarponkeith likes this.
  5. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #5
    This is probably the easiest code to use (allows variables):
    Edit: Just to let you know, you need to create a .htaccess with the code and upload it to the main directory.

    
    RewriteEngine on
    RewriteRule ^something/(.*)/?$ index.php?input=$1
    
    Code (markup):
    The (.*) will become the variable $1 which will be passed to the php script using $_GET[];
    If you want to use more than one variable, you can seperate them with another /, _ or anything else which wont be used in the variable. Example:

    RewriteEngine on
    RewriteRule ^something/(.*)/(.*)/?$ index.php?input=$1&anotherinput=$1
    Code (markup):
    If you just want a simple redirect with variables, you can simple use:

    RewriteEngine on
    RewriteRule ^something somthing.php
    
    Code (markup):
    The above will redirect somthing/ to somthing.php

    I hope that helps!
    Regards
     
    nabz245, Sep 19, 2008 IP
    webrickco and tarponkeith like this.
  6. classic

    classic Peon

    Messages:
    96
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    One of the most common rewrite rules for SEO friendly URLs
    
    
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1
    
    
    HTML:
    So RewriteCond %{REQUEST_FILENAME} !-d means don't apply RW rule if requested URL is directory and the seconds same but for file.


    RewriteRule ^(.*)$ index.php/$1 means anything you get in URI post-pend to index.php

    so URL: like
    http://www.example.com/index.php?module=news&year=2008&category=coding&id=45&page=2

    Will be something like
    http://www.example.com/index.php/news/2008/coding/Optimizing-A-PHP-Code?page=2

    and finally
    http://www.example.com/news/2008/coding/Optimizing-A-PHP-Code?page=2

    so there is a great benefit for SEO , as to search engine id=45 doesn't mean anything but having Optimizing-A-PHP-Code does mean a lot and weights a lot
     
    classic, Sep 19, 2008 IP