问题
I have code below:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (mozilla|navigator|chrome) [NC]
RewriteRule ^newfolder/(.*)$ /index.html [L,NC]
Problem is because it rewrite everything to index.html - it means that picture and external JavaScript won't be seen (loaded)... It only rewrite index.html (text) but other stuff from index not (picture, external JavaScript). With [L,NC,R] work but whith [L,NC] not and I don't want visitors to see that is other page. I want to show visitor full index.html with all it's content - but it is not showing pictures, external JavaScript.
回答1:
You need to 2 RewriteCond
lines to exclude files and directories from this rewrite:
# fixed css/js/images
RewriteRule ^newfolder/((?!index).+?\.(?:jpe?g|gif|bmp|png|tiff|css|js|html?))$ /$1 [L,R=301,NC]
RewriteCond %{HTTP_USER_AGENT} (mozilla|navigator|chrome) [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^newfolder/(.*)$ /index.html [L,NC]
来源:https://stackoverflow.com/questions/21678969/rewrite-showing-only-text-without-pictures-and-external-javascript