What I want:

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

I'm aware that:

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.

Comments

Hm. Just occurred to me I could probably hardcode the %20 in there.

Written by meder

Yep, that's it. Hard code the %20.

Written by John Kugelman

Accepted Answer

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"
Written by jnichols959
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki