Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过index.php路由每个请求(包括图像、css等)_Php_Url_Routing - Fatal编程技术网

通过index.php路由每个请求(包括图像、css等)

通过index.php路由每个请求(包括图像、css等),php,url,routing,Php,Url,Routing,(这里是php新手) 我正在为一个静态营销网站编写一个非常简单的路由器。到目前为止,所有与文件不匹配的请求都会通过我的index.php <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . /index.php [L] <

(这里是php新手)

我正在为一个静态营销网站编写一个非常简单的路由器。到目前为止,所有与文件不匹配的请求都会通过我的index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.php [L]
</IfModule>

重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写规则/index.php[L]
在index.php中,我决定输出什么。这很有效

但是,如果用户专门浏览我不想让他们访问的文件,会发生什么呢?它不会通过我的index.php。所以我可以去掉那个条件。。。但是css文件呢?我猜我也可以包括这些。但是。。。图像呢

我猜有一个更好的方法,我只是还不知道


(一个请求:请不要建议使用框架。在使用其他人的代码之前,我想先了解如何工作。)

更改重写条件以包括排除的文件类型列表:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !\.(png|jpg|gif)$
    RewriteRule . /index.php [L]
</IfModule>

重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写条件%{REQUEST\u FILENAME}!\。(png | jpg | gif)$
重写规则/index.php[L]

谢谢您的回答!所以如果我理解正确,我会用你答案中的内容替换“RewriteCond%{REQUEST_FILENAME}!-f”,对吗?如果我理解正确,这将通过index.php路由除图像之外的每个请求。对吗?最后,我认为css页面和其他东西可以通过索引页面包含,对吗?再次感谢。是的,这是正确的,我会编辑我的答案,任何你没有在(png | jpg | gif)中列出的内容都会传递到index.php。