rewrite showing only text without pictures and external javascript

谁都会走 提交于 2019-12-24 07:46:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!