Tuesday, September 3, 2013

Is slash required at the end of URL?

Actually what happening?:

When you mentioned forward slash(/) at the end of your URL, the server will consider last word as directory and try to enter that directory and try to run index.html or any other index files. If can not found that directory then server try to find a file with that name.

If you do not mentioned forward slash(/) at the end of your URL, the server will consider last word as file and try to run that file. If that file not found then server try to find a directory with that name and then enter.

What problem arrives here?:

As per above two cases, the server will meet two request on following situations,

1. If we provided forward slash(/) at the end of URL, when we had file at the end.
    Example: http://example.com/product/list.php/
    
    (Here the server first try find a folder with the name "list.php", Once it not found then only its try to find a file with the name "list.php".)

2. If we not provided forward slash(/) at the end of URL, when we had directory at the end.
    Example: http://example.com/product/lists

    (Here the server first try find a file with the name "lists", Once it not found then only its try to find a folder with the name "lists".)

Conclusion:

When you are had folder at the end of URL use forward slash(/), otherwise do not use.

Note: You can speed up access to your home page by including the forward slash(/) on your domain name URL. Example: http://example.com/

No comments:

Post a Comment

Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS&l...