htaccess - RewriteRule for static files
how to rewrite urls for images and other static files to specific folder, i.e. I am using this so far:
RewriteRule \.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /MyFolder/$1
but its not working,
please help.
开发者_如何学Python------------------- update ---------------------
ok so now I have:
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteCond %{REQUEST_URI} !^/exmpale.com/
RewriteRule ^(.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /exmpale.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteRule !\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /exmpale.com/index.php
so images redirected to exmpale folders work but now I would like to rewrite everything else to index.php, above solution is not working so far.
cheers, /Marcin
Maybe this is what you want:
RewriteRule ^(.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /MyFolder/$1
or perhaps this:
RewriteRule ([^/]*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /MyFolder/$1
If neither of those is what you're looking for please add details with some examples of your desired inputs/outputs.
As for your update, you probably want to use the L
flag to stop rule processing when this rule matches. eg:
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteCond %{REQUEST_URI} !^/exmpale.com/
# The next line is long. Scroll to the end!
RewriteRule ^(.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ /exmpale.com/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?exmpale.com$
RewriteRule .* /exmpale.com/index.php
You are not capturing the initial request. Try the following:
RewriteRule (.*)\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt)$ /MyFolder/$1.$2
This will get anything that ends in the extension specified and redirect under /MyFolder/
For example: /something/image.jpg
will now go to /MyFolder/something/image.jpg
Note: There may be better ways to do this by adding conditions to check for file type.
精彩评论