Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 如何使用htaccess文件将所有页面重定向到index.html,而不重定向图像文件_Image_.htaccess - Fatal编程技术网

Image 如何使用htaccess文件将所有页面重定向到index.html,而不重定向图像文件

Image 如何使用htaccess文件将所有页面重定向到index.html,而不重定向图像文件,image,.htaccess,Image,.htaccess,如何使用htaccess文件将所有页面(仅页面)重定向到index.html,而不重定向图像文件。由于某些原因,我正在使用此代码,index.html页面上的图像文件没有显示 RewriteEngine on RewriteCond %{REQUEST_URI} !^/index.html$ RewriteRule .* /index.html [L,R=302] 请尝试以下代码: RewriteEngine on RewriteCond %{REQUEST_URI} !^/index.htm

如何使用htaccess文件将所有页面(仅页面)重定向到index.html,而不重定向图像文件。由于某些原因,我正在使用此代码,index.html页面上的图像文件没有显示

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]
请尝试以下代码:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]

在最后一行之前添加以下内容

RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$

保持你的规则简单。与其过滤不应该匹配的内容,不如对文件进行匹配

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .*\.(php|html)$ /index.html [L,R=302]

更好的方法可能是忽略现有文件。例如:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* / [L,R=302]
-d
表示如果存在符合匹配条件的现有目录,则忽略重写

-f
表示如果存在符合条件的现有文件,则忽略重写


其他所有内容都将被重写。

您需要在
public
目录中添加一个
.htaccess
文件,因此每当您构建应用程序时,它都会自动复制到新的
dist
目录。
.htaccess
的内容应如下所示:


RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]


您的第二个条件也应避开圆点
!\。(GIF…。否则,这将停止在这些字符结束的目录上的匹配。考虑使用<代码> [NC] < /Cord>。我在网站管理员上试图问的。谢谢!我把302到301改成了业务:)现在我还需要重定向所有不在根文件夹中的图像。所以/img/*gif | jpg | png应该单独使用,但是/subfolderNotImg | Js | Css应该重定向实际上我应该使用410 Gone而不是重定向。您可能需要添加svg | map | woff2 | woff | ttf。用于加载svg图像、地图文件和Web字体。+1但您可以将
作为
!\。(png | jpe?g | gif | bmp)$[NC]
我已经尽了一切努力来实现这一点。这是第一个这样做的人。非常感谢你。