Reputation: 3488
I have a problem with the regular expression at the bottom. I'm trying to pass all patterns except index.php, robots.txt and any css and js file through the index file, however I have one specific path where I need to process js and css files through php. Normally my url structure is like this:
example.com/class/function
lets say I want to process css and js files from the below pattern:
example.com/view/file/xxxxx.js/css
normally I would have thought this code would work but it doesn't:
(.*)(?!view\/file)(.*)\.(js|css)
for some odd reasons this code work (removed 'view' and added / before (.*)):
(\w*)(?!\/file\/)\/(.*)\.(js|css)
but then I won't be able to load files from the main directory:
example.com/file.js
And when I modify the file like this, it doesn't work again... (all I did was to make / optional):
(\w*)(?!\/file\/)(\/?)(.*)\.(js|css)
Here is the original htaccess file:
RewriteCond $1 !^(index\.php|robots\.txt|(.*)\.(js|css))
RewriteRule ^(.*)$ /index.php/$1 [L]
Upvotes: 0
Views: 1002
Reputation: 6248
For readability and debuggability, I recommend you separate some of your rules.
# Rewrite the special case
RewriteRule ^view/file/(rest of rule)
# Skip these
RewriteRule ^index\.php$ - [L]
RewriteRule ^robots\.txt$ - [L]
RewriteRule ^(.*)\.(js|css)$ - [L]
# Main rule
RewriteRule ^(.*)$ /index.php/$1 [L]
Upvotes: 1
Reputation: 57815
Assuming I have understood correctly, something like this should work:
#rewrite specific css/js
RewriteRule ^view/file/(.*)\.(css|js)$ file.php?file=$1.$2 [L]
#only rewrite anything else if the path is not an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#rewrite to main handler
RewriteRule ^(.*)$ index.php/$1 [L]
Upvotes: 1