How can multiple trailing slashes can be removed from a URL in Ruby
If you just need to remove all slashes from the end of the url string then you can try the following regex:
"http://emy.dod.com/kaskaa/dkaiad/amaa//////////".sub(/(\/)+$/,'')
"http://www.example.com/".sub(/(\/)+$/,'')
/(\/)+$/
- this regex finds one or more slashes at the end of the string. Then we replace this match with empty string.Hope this helps.
How to remove random excess of slashes from url?
Use regular expressions:
require 'uri'
url = URI.parse('https://domain.com/////url/url2')
url.path.gsub! %r{/+}, '/'
p url.to_s
How to remove a URL's trailing slash in a Rails app? (in a SEO view)
I'd use Apache's mod_rewrite. Try this:
RewriteEngine on
RewriteRule ^(.+)/$ $1 [R=301,L]
EDIT: Added R=301. I'm guessing there is an SEO advantage to that vs. the default 302. Remove trailing '/' from rails string
Try:
var apis = '<%= @event.slink.split('-')[-1].gsub(/\/$/, '') %>';
Ruby: How to remove trailing backslashes from a string?
See following code:
1.9.3p125 :022 > s = "cat\\"
=> "cat\\"
1.9.3p125 :023 > puts s
cat\
=> nil
1.9.3p125 :024 > s.chomp("\\")
=> "cat"
1.9.3p125 :025 >
How to make Rails do not ignore trailing slashes in the routes?
I'm not sure why you need your routes to understand that there is a trailing slash. It doesn't matter if you put the trailing slash to Rails. It should respond either way.
If you want all of your links to have a trailing slash, you can put the following in your application.rb:
config.action_controller.default_url_options = { :trailing_slash => true }
This will make all links generated by Rails have a trailing slash. Now, if you're trying to reject any route that does not contain a trailing slash, then I'm not sure about how to do that. how can i remove trailing slashes form the url
To remove a trailing slash using .htaccess
you can use:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
Related Topics
What Are Ruby's Numbered Global Variables
Can't Log into Active Admin. Any Way to Create an Admin User
Generate Models from Existing Tables Using Rails 3
Belongs_To Presence in Rails 5 Not Working
How to Handle Single Table Inheritance in Simpleform So a Single Helper Handles All Models
How Does The "#Map(&Proc)" Idiom Work When Introspecting Module Classes
Unit Testing Code Which Gets Current Time
Error: Spawn Enoent: Missing The SASS Executable
Rails 3. Sort by Associated Model
Paperclip and Amazon S3 How to Do Paths
Using Google Search Rest API in Ruby
How to Include Actionmailer Class in Rake Task
Interpolation Within Single Quotes
Rails and JavaScript Minifier and Aggregator
How to Print a Multi-Dimensional Array in Ruby
Script Executes Successfully in Commandline But Not as a Cronjob