how to get the main path

Discussion in 'PHP' started by PinoyIto, Aug 3, 2008.

  1. #1
    PinoyIto, Aug 3, 2008 IP
  2. CarcaBot

    CarcaBot Active Member

    Messages:
    389
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #2
    U can do lyke this !
    1 : create in ur root directori a file named .htaccess
    2 : add this code :
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^index.html  index.php 
    RewriteRule ^add.html test.php?id=12122121  
    RewriteRule ^go/ test.php?id=11 
    
    Code (markup):
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^index.html index.php //index.php is original url and rezult url is index.html
    RewriteRule ^go/ test.php?id=11 from "test.php?id=11" original url the rezult will be as a folder ...!
    is simple to use :)
    if u need mre help post or pm !
     
    CarcaBot, Aug 3, 2008 IP
  3. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try this example on a seperate file, it will show you all the values you need:

    
    <pre><?php print_r($_SERVER) ?></pre>
    
    PHP:
    The variable you'll be interested in is $_SERVER['HTTP_HOST']

    -----------------------------------
    -----------------------------------

    Sorry, here's what you're looking for:
    <?php
      $url = "http://www.example.com/directory/script?get1=value1";
      $parsed_url = parse_url($url);
    ?>
    <pre><?php print_r($parsed_url); ?></pre>
    PHP:
    the output:
    Array
    (
        [scheme] => http
        [host] => www.example.com
        [path] => /directory/script
        [query] => get1=value1
    )
    
    Code (markup):
    so the value you're interested in is $parsed_url['host']
     
    selling vcc, Aug 3, 2008 IP
  4. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #4
    hello

    maybe this help
    
    <?php
    echo('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['REQUEST_URI']).'');
    ?>
    PHP:
     
    Estevan, Aug 3, 2008 IP
  5. M.Zeb Khan

    M.Zeb Khan Peon

    Messages:
    104
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The thread owner I think asked about manipulation not mod-rewrite.

    so, pinoy, you need to use PHP's eregi_replace(), and some Regular Expression to deal with this.

    Good luck,
     
    M.Zeb Khan, Aug 3, 2008 IP
  6. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #6
    Yes you're right I need to manipulate the url, for example I have site where webmasters can submit a url , instead of getting the entire url including file and parameters.

    meaning remove all files or parameter in the url

    http://www.site.com/?parameter

    remove the /?parameter - http://www.site.com

    or http://www.site.com/folder/file.php
    remove /file.php - http://www.site.com/folder
     
    PinoyIto, Aug 3, 2008 IP
  7. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    $url = "http://www.site.com/?parameter";
    $host = substr($url,0,strpos($url,"/"));
    
    Code (markup):
    result http://www.site.com/

    
    $url = "http://www.site.com/folder/file.php";
    $host = substr($url,0,strpos($url,"/"));
    
    Code (markup):
    result http://www.site.com/folder/

    if you dont want the / on the end do

    
    $url = "http://www.site.com/folder/file.php";
    $host = substr($url,0,strpos($url,"/")-1);
    
    Code (markup):
    result http://www.site.com/folder/

    Untested, but should work in theory.
     
    lfhost, Aug 3, 2008 IP