Apache - Redirect 301 pdf to pdf with spaces ( binary file )
-
19-09-2019 - |
Question
What I want:
To 301 redirect /file_new.pdf to /file new.pdf ( %20 aka space between file and new )
I'm aware that:
- I can rely on RewriteRule 301 which uses mod_rewrite, using a solution from this thread: @ mod_rewrite with spaces in the urls
- I can rename the file to not include spaces and replace them with dashes/underscores
However, I'm personally curious as to how one would do this. 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 I invoke the configtest:
Redirect takes two or three arguments, an optional status, then document to be redirected and destination URL
Edit: Apparently the mod_rewrite nor Redirect 301 methods are working for me, possibly because for whatever reason they aren't applying because the file actually exists in 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 to each respective uri / http request.. I think something is taking control before it even gets to the mod_alias/mod_rewrite stuff.
So to sum it up, it goes directly to file_new.pdf in the browser and doesn't 301. I'm positive that alias
and rewrite
are enabled. My apache version is 2.2.
Solution
the Redirect
is actually part of mod_alias, not mod_rewrite. i'm glad the %20 worked and you can also use quotes to tell apache that the path that includes the space is the URL to redirect to and not two separate items:
Redirect 301 /pdf/file_new.pdf "http://site.local/pdf/file new.pdf"