KleverKrypto
KleverKrypto

Reputation: 518

.htaccess Redirect entire directory except pdf files

I'm trying to redirect everything in directory2 (/directory1/directory2/) except for PDF files to a static URL. Is this possible?

Upvotes: 1

Views: 394

Answers (1)

anubhava
anubhava

Reputation: 785128

Yes it is possible. Place this code in root .htaccess:

RewriteEngine On

# it doesn't end with .pdf
RewriteCond %{REQUEST_URI} !\.pdf
# URI starts with /directory1/directory2 then redirect
RewriteRule ^directory1/directory2/(.*)$ /some-where/$1 [L,NC,R]

Upvotes: 2

Related Questions