Skip to main content

Forums

This topic contains 9 replies, has 4 voices, and was last updated by  bearhead 4 years, 7 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #199847

    bearhead
    Participant

    On the website I’m working on, if I type in a url like: mydomain.com/home, my web browsers automatically place a slash at the end of home which is not what I want. Is there a way to over-ride this behavior? Is it something that needs to be changed in my server settings?

    The website is running on an iis7 server (unfortunately it’s shared, so there are restrictions on what settings can be modified).

    #199848

    Senff
    Participant

    This reply has been reported for inappropriate content.

    It’s fairly normal behavior. For example, if you go to http://www.marksenff.com/front-end/jquery-plugin-sticky-anything (without trailing slash), the site will add the trailing slash.

    I don’t think it’s something your web server does, but what the site software does (in my case, WordPress), or the browser.

    I’m not sure if that’s something that you can override, so I can’t really give a solution to your problem, but I’m wondering why it’s a problem for you?

    #199849

    shaneisme
    Participant

    This reply has been reported for inappropriate content.

    If it’s IIS, you’d need access to the server to set up a rewrite rule.

    You might be able to edit a web.config in your site’s folder, but I’m not 100% sure on that.

    Google around for IIS remove trailing slash (or web.config).

    #199855

    bearhead
    Participant

    This reply has been reported for inappropriate content.

    Senff, I’m actually not using wordpress or any CMS, which leads me to believe that the slash is coming from a server setting (like shane suggested). Its a problem for me because the site has one point of entry and the links are setup like so: “domain/index.php/page”. I want to lose the index.php in the url to make it look cleaner. However a url like “domain/page” gets the slash added, so the server loads the default document in that directory instead of staying on the root index.php, and executing my front loader script.

    ok, thanks shane, I’ll look into doing via the web.config file.

    #199885

    __
    Participant

    This reply has been reported for inappropriate content.

    This is simply how URLs are supposed to work. Apache (other servers too afaik) adds the trailing slash by default when it is missing because that is the correct form. In fact, you can mess up relative URLs if you leave it off.

    For example, say you’re on your /blog page (NO trailing slash) and you have a link to your most recent post:

    <a href="latest">My Latest Blog Post</a>

    it won’t go to /blog/latest as expected; it will go to /latest. /latest wouldn’t work; not even ./latest would work. You’d have to use absolute URLs everywhere: /blog/latest.

    My recommendation would be to not try to re-invent the way the internet works. Rather, your routing system should expect the trailing slash, and make it optional in case it is ever missing.

    the server loads the default document in that directory instead of staying on the root index.php

    If you are using a single-point-of-entry (which is good), why do you have other directories/files in your web root? Your index.php should be the only script accessible from the web.

    #199911

    bearhead
    Participant

    This reply has been reported for inappropriate content.

    Yeah, its kind of a goofy system I have going on… I know that my data should be in a mysql database or the like, but because of things out of my control, I don’t have access to anything like that. The Hosting plan we have is really meant for a static website, so I have like this weird hybrid system going on, where the website data is stored in php files on the server.

    Our website doesn’t have a login system or anything like that, so there isn’t any sensitive information being stored.

    But, yes, I need to approach this differently. One thing that I did learn is that the slash only gets added if the directory is a “real” one. A “virtual” directory doesn’t have the slash automatically added.

    My real issue is that I don’t want “index.php” to be displayed in my urls, so maybe all I need to do is set index.php as the default file?

    or maybe with the weird system I have built, it’s just not possible.

    #199912

    shaneisme
    Participant

    This reply has been reported for inappropriate content.

    You should be able to set up a rewrite rule for that, but I hope whatever data you have isn’t important at all.

    #199913

    bearhead
    Participant

    This reply has been reported for inappropriate content.

    Its data that is rendered by the browser when a user visits a page. I guess someone could rummage through the data files, but all that information is displayed to the general public anyway, so whats the point?

    Basically, all I’ve done is taken a static website and separated the content from the layout to make it more maintainable.

    #199922

    __
    Participant

    This reply has been reported for inappropriate content.

    Does this host allow you access to directories “above” your document root (directories which are not accessible from the web)? If so, put all your stuff there, and leave only your index.php file in the document root. Then you can rewrite all requests to go to index.php. (If you have static assets —e.g., images, stylesheets, javascript— you can make an exception to this and serve them directly.) As I mentioned above, the quickest and most effective way to solve the trailing slash “problem” would be to simply allow all of your routes to have a trailing slash.

    Basically, all I’ve done is taken a static website and separated the content from the layout to make it more maintainable.

    Admirable. : )

    Your hosting plan sounds very limited. I hope it’s a “free” plan because, if you’re paying for it, you could almost certainly do better for the same cost. Keep in mind that VPS’s can be had for as little as $5/month these days.

    #199924

    bearhead
    Participant

    This reply has been reported for inappropriate content.

    I’m not sure about above the root directories. I can look into it.

    one idea I had was to edit the web.config file to deny any url sequence with a .php in it.

    <denyUrlSequences>
    <add sequence=".php" />
    </denyUrlSequences>

    of course, the problem there is that it also blocks access to index.php… so maybe if I could somehow block all .php but index.php?

    adding

    <alwaysAllowedUrls>
    <add url="index.php" />
    </alwaysAllowedUrls>

    doesn’t seem to work.

    edit:
    got the index.php out of the url using rewrite in the web.config file.

    I also prevented direct access to specific php files using the deny url sequence described above.

    Thanks for the help and ideas!

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star