简体   繁体   English

.htaccess将所有内容重写为index.php或静态文件

[英].htaccess rewrite everything to index.php or static files

My .htacces is setted to handle all request to index.php 我的.htacces设置为处理对index.php的所有请求

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [QSA,L]

Is working right but now I found myself in a situation that I need make the files from img folder accessible from url, follow my folder structure and the new line on .htaccess: 工作正常,但现在我发现自己处于一种状况,需要使img文件夹中的文件可从url访问,并遵循我的文件夹结构和.htaccess上的新行:

Folder Structure 资料夹结构

.htaccess // File
index.php // Folder
webroot // Folder
  img // Folder inside webroot

.htacess .htacess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^webroot/.+\.(jpg|gif|png|ico)$ - [L] // New line

RewriteRule ^ index.php [QSA,L]

htaccess says if I get http://example.com/webroot/img/something.jpg goes to, if not handle anything else to index.php. htaccess说,如果我进入http://example.com/webroot/img/something.jpg ,如果无法处理index.php的其他内容,请访问htaccess。

How can I access my statics files without call webroot on url? 如何在不调用url的webroot的情况下访问我的静态文件? like this http://example.com/img/something.jpg with my current folder structure?? 像这样的http://example.com/img/something.jpg和我当前的文件夹结构?

You could try this if you want to remove webroot from url. 如果要从网址中删除webroot ,可以尝试此操作。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^img/(.*)$ /webroot/img/$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM