rack-rewrite is a Rack middleware that provides URL rewrite rules to Rack apps. It is a little bit like mod_rewrite for Apache.
Questions tagged [rack-rewrite]
21 questions
0
votes
1 answer
Rails - How to stop Rack Rewrite gem persisting between projects?
I'm using the excellent Rack Rewrite gem in one of my Rails projects.
I used it to rewrite http requests to https://whatever.tld.
Here's the snippet from config/application.rb:
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
…

TerryS
- 7,169
- 1
- 17
- 13
0
votes
2 answers
Is it possible to use rack-rewrite for rewriting just POST requests?
That's it. I need to redirect just the POST requests. Something like:
rewrite /.*/, '/universal_POST_handler', :if => (something_cool_goes_here)
Is it possible?

Erik Escobedo
- 2,793
- 24
- 42
0
votes
1 answer
rack-rewrite 301 not matching for specific query
Can any one tell me why this works:
r301 %r{(?:images\/)(\d*.jpe?g|png|gif)$}, 'http://mybucket.s3.amazonaws.com/540x310/$1'
URI = http://www.mysite.com/images/42720.jpeg
and this doesn't
r301 %r{(?:resized_images\/\d*x\d*\/)(\d*.jpe?g|png|gif)$},…

dp6ai
- 41
- 3
0
votes
0 answers
Rack-rewrite use regex in condition RoR 3.1
I'm trying to set the following rule for redirection:
if Rails.env.staging? || Rails.env.production?
r301 %r{.*}, 'http://mysite.com$&', :if => Proc.new {|rack_env|
rack_env['SERVER_NAME'] != 'mysite.com' &&…

content01
- 3,115
- 6
- 41
- 61
-1
votes
2 answers
Rails, how to set root_path as ' '
For SEO purposes I want the the root_path to be ' '. In other words, I'd like the canonical homepage URL to be domain.com instead of domain.com/. I tried to set
# routes.rb
get '' => 'home#index', as: :root
#…

franksort
- 3,093
- 2
- 19
- 27
-1
votes
1 answer
How to force all request to come from my website to avoid spoofing in RoR 3.2
my site just got spoof.
I'm using RoR 3.2.11 and I installed the rack-rewrite gem.
I created the /middleware dir inside /app and I created a .rb file inside.
Now, how should I write the rule to only allow requests coming from my page?
Thanks!

content01
- 3,115
- 6
- 41
- 61