how define in htacess a link that don´t exist?

Discussion in 'PHP' started by srdva59, Aug 12, 2009.

  1. #1
    hi,
    i have this domain for example: mydomain.com
    and i want when i enter this url in browser:

    mydomain.com/test

    the htacess see the "test" redirect the site for test location ex: www.silva.com
    and to that for the other words that i enter after "/"
    for the folders that exist in server the htacess will don´t do nothing
    the objective is only for the words what i want
    this is possible?
    thanks for your help
    :)
     
    srdva59, Aug 12, 2009 IP
  2. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #2
    What exactly are you trying to do?
    You left that part out :p

    There might be a better way to accomplish your task.
     
    zac439, Aug 12, 2009 IP
  3. badeyes

    badeyes Active Member

    Messages:
    411
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    what is test.. a file, folder or what? explain it first if you want help on it.
    and who's site is silva dot com?
     
    badeyes, Aug 12, 2009 IP
  4. metabinltd

    metabinltd Well-Known Member

    Messages:
    146
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #4
    put in .htaccess the following:

    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /controller.php [L]
    </IfModule>
    
    Code (markup):

    then in controller.php put the following

    
    if($_SERVER["REDIRECT_URL"]=='/test/'){
    //do this
    }
    
    Code (markup):
     
    metabinltd, Aug 12, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5

    This is similar to how wordpress handle's friendly URLs in .htaccess

    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    Code (markup):
    See the two RewriteCond lines ending in !-f and !-d
    Those conditions mean as long as the filename is not an existing directory or existing file. If they are, then it skips the rule and goes straight to that file or folder.
     
    kblessinggr, Aug 12, 2009 IP