I have some URLs, like www.amazon.com/
, www.digg.com
or www.microsoft.com/
and I want to remove the trailing slash, if it exists, so not just the last character. Is there a trim
or rtrim
for this?
replace(/\/+$/, '') . The replace method will remove the trailing slash from the string by replacing it with an empty string.
A 301 redirect is the best way to resolve duplicate content issues caused by trailing slashes. If you're just fixing one page, you'd redirect the duplicate copy to the version that matches your chosen URL structure. Most trailing slash issues however, affect many pages across a website.
The trailing slash does not matter for your root domain or subdomain. Google sees the two as equivalent. But trailing slashes do matter for everything else because Google sees the two versions (one with a trailing slash and one without) as being different URLs.
Email Subscription. A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the trailing slash.
You put rtrim
in your answer, why not just look it up?
$url = rtrim($url,"/");
As a side note, look up any PHP function by doing the following:
(rtrim
stands for 'Right trim')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With