Apache - redirect 301 pdf to pdf with spaces (binary)

What I want:

In 301 redirect / file _new.pdf to / file new.pdf (% 20 aka space between file and new)

I know that:

  • I can rely on RewriteRule 301 which uses mod_rewrite using the solution from this thread: @ mod_rewrite with spaces in urls
  • I can rename the file to not include spaces and replace them with dashes / underscores

However, I am personally wondering how this can be done. Here's what I have so far:

Redirect 301 /file_new.pdf http://sitename.com/file\ new.pdf

      

The conf file parser throws an error when calling configtest:

The redirect takes two or three arguments, an optional status, then the document to be redirected and the target URL

Edit: Apparently the mod_rewrite or Redirect 301 methods work for me, perhaps because they don't apply for some reason, because the file actually exists at that location.

<VirtualHost *:80>
DocumentRoot /www/sitename_com
ServerName site.local
Options -MultiViews

RewriteEngine on
Redirect 301 /pdf/file_new.pdf http://site.local/pdf/file%20new.pdf
RewriteRule ^/pdf/file_new.pdf http://site.local/pdf/file\ new.pdf
RewriteLog "/www/rewrite.log"
</VirtualHost>

      

In rewrite.log, it tries to match the pattern with every matching uri / http request. I think something is taking control before it even gets into the mod_alias / mod_rewrite stuff.

So, to sum it up, it goes directly to the_new.pdf file in the browser and not 301. I'm sure alias

and rewrite

are included. My apache version is 2.2.

+2


source to share


1 answer


Redirect

is actually part of mod_alias, not mod_rewrite. I'm glad% 20 worked, and you can also use quotes to tell apache that the path that the space includes is the URL to redirect, not two separate items:



Redirect 301 /pdf/file_new.pdf "http://site.local/pdf/file new.pdf"

      

+5


source







All Articles