Reputation: 10163
I have searched and searched but for some reason can not get this to work how I need it to. I need to write a rule in htaccess that checks to see if the file exists and if it does not look in a subdirectory of the original directory. For example if the request is:
www.mysite.com/css/main.css
if the file main.css is not found I need to redirect to
www.mysite.com/css/src/main.css
I have tried this in my .htaccess in the /css/ directory
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^css/?([^/].+)?$ /css/src/$1 [L,R=301]
Seams to me that this should be a very easy task but can not seem to get this working. Also in regards to debugging htaccess how to I log what the rewrite rule is looking for? I have this in my VirtualHost file:
LogLevel trace4
but this does not show where the rewrite rule is trying to go... Thanks for the help!
Upvotes: 1
Views: 64
Reputation: 10163
I was able to figure this out, the problem I was having was the redirect here is my .htaccess file in case anyone is having a similar problem:
In my css directory I have the following .htaccess:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/].+)?$ src/$1 [L]
Upvotes: 0
Reputation: 784918
Your regex doesn't seem right. Use this rule:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^css/([^/]+)$ /css/src/$1 [L,R=301,NC]
For your second part you need:
LogLevel trace4
RewriteLog "/val/logs/rewrite.log"
Upvotes: 1