Eeliya
Eeliya

Reputation: 1574

Redirect url if it has specific extension

How can I redirect URLs which has extension like .css or .js but not .php to specific folder.

I mean all the URLs which has extension but their extension is not php should be redirect to specific folder.

I try to do it like this but it does not work:

RewriteCond %{REQUEST_URI} \.(.{2,4}!php)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)\.(.{2,4}!php)$ folder/$1.$2 [L]

Upvotes: 0

Views: 66

Answers (2)

Jon Lin
Jon Lin

Reputation: 143856

Your regex isn't right, you want simply !\.php$:

RewriteCond %{REQUEST_URI} \.\w{1,4}$
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ folder/$1 [L]

Upvotes: 0

Eeliya
Eeliya

Reputation: 1574

Well I have found the solution:

RewriteCond %{REQUEST_URI} \.(.{2,4})$
RewriteCond %{REQUEST_URI} !\.(php)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [L]

First I check if the extension is in desire length, then I check it is not end with .php

Upvotes: 1

Related Questions