LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-28-2018, 10:05 AM   #1
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Rep: Reputation: 0
Slashes in a URL


This has always confused me...

In a "clean URL" which only has words and slashes, when should there be a trailing slash?

Or asked another way, if you saw the follwoing URLs, would they each be valid and what would the say to you?

http://www.mysite.com

http://www.mysite.com/

http://www.mysite.com/products

http://www.mysite.com/products/

http://www.mysite.com/products/mens

http://www.mysite.com/products/mens/


I am working with Apache mod_rewrites and better understanding the above will help to make sure my rewrites yield the proper results!

Thanks.
 
Old 12-28-2018, 10:10 AM   #2
Lysander666
Senior Member
 
Registered: Apr 2017
Location: The Underearth
Distribution: Ubuntu, Debian, Slackware
Posts: 2,178
Blog Entries: 6

Rep: Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470
EDIT: I'm as confused as the OP. Would be interesting to see what others have to say on this.

Last edited by Lysander666; 12-28-2018 at 10:14 AM.
 
Old 12-28-2018, 10:15 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
@Lysander666,

CTRL-T, CTRL-L <type stuff>

That's about all I ever do.

I agree, leave out the trailing slash. Yes it doesn't matter much, however the rare cases where it does make it not worth adding it in.

I type "usatoday.com[RET]" and it brings me to https://www.usatoday.com

CTRL-W
 
Old 12-28-2018, 10:22 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
It really doesn't matter in my eyes because the web server in question will interpret the URL how it sees fit, even redirecting to a canonical URL (by adding a final slash or taking it away) if it feels like it.

For example, http://www.mysite.com/products/ may point at a directory on the web server, or a file, or some code, or whatever. It doesn't matter - the thing that matters is that the web server interprets it and you get web content in return.

Personally, my canonical URL form for my sites is to remove any trailing slash, but only for aesthetic reasons as I think it looks nicer that way.
 
Old 12-28-2018, 10:23 AM   #5
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Original Poster
Rep: Reputation: 0
Why are you guys having a side conversation in my thread?

I don't even understand what you were talking about with Ctl T and whatever?

Can we please get back to my OP and examples?
 
Old 12-28-2018, 10:27 AM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Adirondacks View Post
Why are you guys having a side conversation in my thread?

I don't even understand what you were talking about with Ctl T and whatever?

Can we please get back to my OP and examples?
IMO the previous posts are on-topic and helpful...but if you want information about what happens on the server with and without a trailing / (and therefore how it might affect your mod rewrite), suggest you review the Apache documentation.
Also this search pulled up some useful information.

Better?
 
Old 12-28-2018, 10:29 AM   #7
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hydrurga View Post
It really doesn't matter in my eyes because the web server in question will interpret the URL how it sees fit, even redirecting to a canonical URL (by adding a final slash or taking it away) if it feels like it.

For example, http://www.mysite.com/products/ may point at a directory on the web server, or a file, or some code, or whatever. It doesn't matter - the thing that matters is that the web server interprets it and you get web content in return.

Personally, my canonical URL form for my sites is to remove any trailing slash, but only for aesthetic reasons as I think it looks nicer that way.
But this is a big deal, because it affects how I am writing my mod_rewrites and regex!

This is my understanding...

Whether the hostname ends with a slash isn't really important, so either of these will do...

http://www.myexample.com

http://www.myexample.com


If a URL has stuff after the hostname, then if things end with a slash, that implies the last part if a directory...

http://www.myexample.com/products/


And if a URL has stuff after the hostname, and things do not end with a slash that impies a file...

http://www.myexample.com/products/mens



I have a mod_rewrite that I am trying t better understand, and knowing the answer to the above will shape how I tweak that code.

(This whole Apache rewrite things yeilds nice looking end results but sure can be a PITA sometimes!!)
 
Old 12-28-2018, 10:34 AM   #8
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by scasey View Post
IMO the previous posts are on-topic and helpful...
In post #2, Lysander666 says, "EDIT: I'm as confused as the OP. Would be interesting to see what others have to say on this."

Then in post #3, rtmistler says, "@Lysander666,

CTRL-T, CTRL-L <type stuff>

That's about all I ever do.

I agree, leave out the trailing slash. Yes it doesn't matter much, however the rare cases where it does make it not worth adding it in.

I type "usatoday.com[RET]" and it brings me to https://www.usatoday.com

CTRL-W"


What in the hell does all of that mean??

That isn't even a coherent conversation?!

Sounds like there are missing posts or some prior conversation that leaves me in the dark dealing with my OP?!
 
Old 12-28-2018, 10:39 AM   #9
Lysander666
Senior Member
 
Registered: Apr 2017
Location: The Underearth
Distribution: Ubuntu, Debian, Slackware
Posts: 2,178
Blog Entries: 6

Rep: Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470Reputation: 2470
OP, calm down.

There have been some useful responses.

In short OP, leave out the trailing slash is the consensus.

I should have kept my original post in because it may have been helpful.

For instance, in the following examples

https://en.wikipedia.org/wiki/Fish

works whereas

https://en.wikipedia.org/wiki/Fish/

does not. This is because the Wikipedia server sees "Fish/" as a distinct file name.

Last edited by Lysander666; 12-28-2018 at 10:55 AM.
 
Old 12-28-2018, 10:40 AM   #10
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
From my experience, it also depends on application itself. Although, most of the apps where I've noticed a trailing / is needed are all IIS/ASP applications.
Since, this is for your server and application developed by developers at your org, may be test or ask the developers weather or not a trailing / is required, that should help narrow down your options?
 
Old 12-28-2018, 10:40 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Adirondacks View Post
But this is a big deal, because it affects how I am writing my mod_rewrites and regex!
Well you should test your code. Write small portions of it to test and validate what happens for each condition you're worried about.

While I may solicit opinions from fellow developers or an online forum, I can assure you that while I may agree or disagree with offered opinions, I will always test my code. More helpful might be the additional perspectives given to me by other persons or posters which would help me to more completely test my code.

So while we get it that this is important, it is important to you, and thus rather than just take anyone's word for it, you should follow up on references offered to validate the information. And since you're writing actual code, I'll repeat the primary recommendation, which is to test it.

Also as scasey says, you can research a lot of this in the documentation.

Last edited by rtmistler; 12-28-2018 at 10:45 AM.
 
Old 12-28-2018, 10:40 AM   #12
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Adirondacks View Post
In a "clean URL" which only has words and slashes, when should there be a trailing slash?
It essentially tells the web server that the url is of a DIRECTORY (on that server) and that it should load the default file IN that directory (often index.html, but other names could have been configured, like index.php). Some websites will not work without that trailing slash for a directory although other servers won't mind.
Of course an url which ends on a clear FILEname never should have a trailing slash.
 
1 members found this post helpful.
Old 12-28-2018, 10:43 AM   #13
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Perhaps due to the URL format's UNIX-origins the trailing slash used to imply a directory and the lack of it implied a file, but that is no longer the case. It can be either or neither these days, the URL often pointing at nothing in particular, just providing some server-side code with an indication about which resource it should serve up.

In the practical world, just decide on how you want your URLs to be canonically and stick to it for the sake of consistency. Browsers won't give a hoot anyway if there is a trailing slash or not.

As far as SEO is concerned: https://webmasters.googleblog.com/20...-to-slash.html
 
1 members found this post helpful.
Old 12-28-2018, 10:52 AM   #14
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rtmistler View Post
Well you should test your code. Write small portions of it to test and validate what happens for each condition you're worried about.

While I may solicit opinions from fellow developers or an online forum, I can assure you that while I may agree or disagree with offered opinions, I will always test my code. More helpful might be the additional perspectives given to me by other persons or posters which would help me to more completely test my code.

So while we get it that this is important, it is important to you, and thus rather than just take anyone's word for it, you should follow up on references offered to validate the information. And since you're writing actual code, I'll repeat the primary recommendation, which is to test it.

Also as scasey says, you can research a lot of this in the documentation.
I didn't ask what works. (Therefore tesing isn't the issue...)

I am asking what is the "right" way to do things. There is a difference.

And fwiw, I have been buried in the Apache manual for the last few days.

Of course, developers are horrible at documenting things, thus I have to ask here about things that the manual should tell me.
 
Old 12-28-2018, 10:53 AM   #15
Adirondacks
Member
 
Registered: Oct 2018
Posts: 98

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ehartman View Post
It essentially tells the web server that the url is of a DIRECTORY (on that server) and that it should load the default file IN that directory (often index.html, but other names could have been configured, like index.php). Some websites will not work without that trailing slash for a directory although other servers won't mind.
Of course an url which ends on a clear FILEname never should have a trailing slash.
In the past, that has been my understanding too...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Replacing "slashes" with back slashes - escape character problem kushalkoolwal Programming 2 01-08-2011 01:16 AM
regular expression that matches forward slashes? zero79 Linux - Software 4 12-24-2005 11:43 AM
What do two forward slashes in a url mean? (not the inital 2) johnMG Linux - Networking 2 06-28-2005 10:27 AM
bash and double slashes MD3 Linux - Software 0 02-18-2005 03:13 PM
Forward slashes in filenames. Convert from 2f to Colon chrisk5527 Linux - General 3 03-26-2004 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration