Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts

    How to remove script from url

    My script is on localhost in file script.php
    When i call it either with

    Code:
    http://script_path/
    
    or
    
    http://script_path/script.php
    it returns the same page

    Now i have a set of links

    Code:
    http://script_path/script.php/home
    http://script_path/script.php/tv-shows
    http://script_path/script.php/theater
    etc..
    each of those links shows something different

    Is it possible to write some kind of .htaccess file so that those links become same as

    Code:
    http://script_path/home
    http://script_path/tv-shows
    http://script_path/theater
    etc..
    and if someone directly types
    Code:
    http://script_path/script.php
    
    or
    
    http://script_path/script.php/home
    he gets 404 error

    thank you

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Is it possible to write some kind of .htaccess file so that those links become same as [...]
    Showing your current rules and some relevant code would be helpful.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    I have no relevant code, it's new project i'm trying to finish now.

    Only thing that can maybe be relevant is that i'm using $_SERVER['REQUEST_URI'] compared to $_SERVER['SCRIPT_NAME'] to load content..

    EG:
    This code is what i have in mind..

    PHP Code:
    <?php
    define 
    ("NOPAGE""home");

    $script $_SERVER['SCRIPT_NAME'];
    $path    $_SERVER['REQUEST_URI'];


    if (
    strlen($script) >= strlen($path)) {
        
    load (NOPAGE$script);
    }
    else {
        
    $page substr($pathstrlen($script));
        
    load ($page$script);
    }

    function 
    load($content$script) {
        if (
    $content == NOPAGE || $content == "/") {
            print 
    "LOAD DEFAULT PAGE";
        }
        else {
            print 
    $content;
        }
    }
    ?>
    Basicly it is simple way to get everything behind trailing slash of script, in this example if you write
    Code:
    http://some_random_path/
    http://some_random_path/script.php
    Script will return default value for that page
    BUT
    Code:
    http://some_random_path/script.php/TV-Shows
    Script will return
    /TV-Shows

    Also some_random_path directory has .htaccess rule that only sets
    script.php to be directory index, and no other rewrite or similar rules reside in that directory.

    By using simple rule as
    Code:
    <Files script>
    sethandler application/x-httpd-php
    </Files>
    I can remove trailing.php slash so link can look something like
    Code:
    http://some_random_path/
    http://some_random_path/script
    http://some_random_path/script/TV-Shows
    and still have the same effect as example above.

    Now if i could only force apache not to show that script path, and still do the same, it could be the new best thing for me
    Last edited by funnymoney; 03-15-2009 at 07:44 PM.

  • #4
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    any luck

  • #5
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Managed to solve this problem!

    Solution is this rewrite rule

    RewriteRule ^(.*)$ script


  •  

    Posting Permissions

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