Click to See Complete Forum and Search --> : [RESOLVED] .htaccess redirect *.pdf to /newdir/*pdf


mameha1977
01-24-2007, 02:21 AM
I want to redirect all requests for .pdf files from one dir to another.

OLD DIR: www.domain.com/en/product/pdf/
NEW DIR: www.domain.com/global_pdf/

...so when someone requests:
www.domain.com/en/product/pdf/john.pdf

it loads:
www.domain.com/global_pdf/john.pdf

I think I need to use RedirectMatch or RedirectRule to check for *.pdf but I have no idea how to write the expression matching thing.

Can anyone help with this?

coppocks
01-24-2007, 03:24 AM
Take a look at this page for several examples:

http://www.webweaver.nu/html-tips/web-redirection.shtml

I'd try something like this:
redirect /en/product/pdf/ http://www.domain.com/global_pdf/

pcthug
01-24-2007, 03:34 AM
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]
Should do the trick.

mameha1977
01-24-2007, 04:01 AM
ok, im not sure what the syntax is or how to learn about that (ie what is [L], $1 etc).

But I'll try this and get back to you, thanks a lot!

pcthug
01-24-2007, 04:30 AM
Ok, I will explain the code step by step.

Tell the web server to accept Rewrite statements
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Pass the web server a Rewrite rule
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Start of string
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Only redirect all requests with the URI Base (always the same [static]) of en/product/pdf/
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

New Group Section
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

. = Any one character
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

+ = One or more of the previous character
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Escape succeeding character (forces the web server to treat the succeding character as a literal one)
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Only redirect requests that have the .pdf extension
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

End of string
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Redirect to URI with the the URI Base (always the same [static]) global_pdf/
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Value of Group 1 (the (.*\.pdf) part)
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

Flag the Rewrite rule as the Last Rule
RewriteEngine on
RewriteRule ^en/product/pdf/(.+\.pdf)$ global_pdf/$1 [L]

mameha1977
01-24-2007, 08:50 PM
Thanks for this, I had some trouble with the paths but once that was sorted it worked fine.

Thanks for the explanations too!