/    Sign up×
Community /Pin to ProfileBookmark

Adding slashes behind a filename

Say I have a file “index.php”. And I access it just fine (e.g. “http://www.domain.tld/index.php“) and nothing’s wrong with it. Now say some bozo tries to get cute with the URL, appending another file/directory to it (e.g. “http://www.domain.tld/index.php/another/file“). My server attempts to serve whatever it thinks that URL requests, which results in a horrible-looking page since all of my relative links and sources then point to the invalid directory (in this example: “http://www.domain.tld/index.php/another/“, so if I want “index.css”, the browser requests “http://www.domain.tld/index.php/another/index.css“, which doesn’t exist). What settings would I have to change to cause a request like this to return an error?

I’ve posted this in the PHP forum because I tested this behavior with a normal “htm” file and received a 404 Error.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 27.2007 — Are you doing some sort of Apache mod_rewrite stuff for .php files?
Copy linkTweet thisAlerts:
@palswimauthorMar 27.2007 — My main server isn't my own, so I'm not sure there. I checked the httpd.conf file on my testing servers and didn't have mod_rewrite loaded and everything else referencing php is just the normal stuff.
Copy linkTweet thisAlerts:
@NogDogMar 27.2007 — I don't know enough about webserver processing to have any idea why such URIs do not also just result in a 404 Not Found. Only thing I have to suggest until some expert comes up with an explanation (and hopefully solution) is to add a BASE element to the page's HEAD section, so that the browser knows from where relative links should be resolved:
<i>
</i>&lt;head&gt;
...
&lt;base href="http://www.domain.tld/index.php"&gt;
...
&lt;/head&gt;
Copy linkTweet thisAlerts:
@DARTHTAMPONMar 27.2007 — not sure if this helps but try something like this

$veriable = @preg_replace('/(.+)/(.+)$/','1',$_SERVER['PHP_SELF']);

if ($veriable != "/")

{

echo "<br><br>redirect";

}
×

Success!

Help @palswim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...