...

View Full Version : How to remove script from url



funnymoney
03-15-2009, 11:52 AM
My script is on localhost in file script.php
When i call it either with


http://script_path/

or

http://script_path/script.php

it returns the same page

Now i have a set of links



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



http://script_path/home
http://script_path/tv-shows
http://script_path/theater
etc..


and if someone directly types


http://script_path/script.php

or

http://script_path/script.php/home

he gets 404 error

thank you

abduraooft
03-15-2009, 01:14 PM
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.

funnymoney
03-15-2009, 08:42 PM
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
define ("NOPAGE", "home");

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


if (strlen($script) >= strlen($path)) {
load (NOPAGE, $script);
}
else {
$page = substr($path, strlen($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


http://some_random_path/
http://some_random_path/script.php

Script will return default value for that page
BUT


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

<Files script>
sethandler application/x-httpd-php
</Files>

I can remove trailing.php slash so link can look something like


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 :)

funnymoney
03-16-2009, 08:19 PM
any luck

funnymoney
04-02-2009, 04:07 PM
Managed to solve this problem!

Solution is this rewrite rule

RewriteRule ^(.*)$ script



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum