2

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.

Community
  • 1
  • 1
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434

1 Answers1

5

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"
jnichols959
  • 402
  • 4
  • 12
  • I'm aware `Redirect` is part of `mod_alias` as I initially tagged it for mod-alias, it actually didn't work for whatever reason, perhaps something in my Virtualhost? I didn't really tinker around too much with the default httpd.conf, this is on a fresh Lenny debian box. I'll try your method and see if it works. – meder omuraliev Oct 05 '09 at 21:35