- dist
- js
- css
- index.php
- .htaccess
我不想移动index.php
,/dist
因为 dist 文件是由 Vue.js 构建的,并从 git 等中排除。
我试图在 Google 和 Apache 文档的帮助下使其工作数小时,但失败了。
RewriteEngine On
RewriteRule ^(app|dict|ns|tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_URI} .(css|js)$
RewriteRule ^(.*.(css|js))$ /dist/$1 [QSA,L]
RewriteRule ^ index.php [QSA,L]
它将所有需要的请求重写到index.php
,但 js 和 css 抛出一个错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
阿帕奇日志:
[Fri Aug 16 23:10:06.973003 2019] [core:error] [pid 10716:tid 996] [client 127.0.0.1:2106] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
正如标题所说,我想在所有资产前加上\dist
文件夹,否则重写为index.php
.
我查看了回溯,这是更改后的结果:
RewriteEngine On
RewriteRule ^(app|dict|ns|tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_URI} ^(?!dist\/?).*.(css|js|map)$
RewriteRule ^((?!dist\/).*.(css|js|map))$ /dist/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
它有效
事情是
当规则的目标与初始重写模式匹配时, RewriteRule 循环。例如,如果您要将所有以“foo”开头的 URL 重写为“foo.php”,那么“foo.php”也将被重写为“foo.php”,以此类推,直到永远。
如果你遇到这个,你应该查看源代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句