# 常见问题

# 一、首页提示请求地址出错:xxxx

# 达成条件

# 问题解决

  • 如果你使用宝塔面板,请登录宝塔面板->网站->伪静态 中选择thinkphp的伪静态规则即可。
  • 如果你使用lnmp.org的一键安装LNMP环境,请同时参考官网文档 (opens new window)进行伪静态规则配置
  • 以下罗列了Nginx、Apache、IIS的URL重写配置方式。
# [ Nginx ] 配置
# Nginx站点配置文件
server {
    listen        80;
    server_name   ba.com;
    root   "D:/WWW/ba.com/public";
    location / {
        # 将 index.html 放在第一位可以实现隐藏 index.html
        index index.html index.php error/index.html;

        # 这一段即为 URL重写规则 请确保存在
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
        # 结束
    }

    # 已省略余下代码
}
# [ Apache ] 配置
  1. httpd.conf配置文件中加载了mod_rewrite.so模块
  2. 站点对应的conf文件中AllowOverride NoneNone改为All
  3. 把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下(public目录
<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>
# [ IIS ] 配置
  1. 安装url-rewrite (opens new window)
  2. 站点根目录(public目录)建立web.Config文件,写入以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="BuildAdmin" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="index.php" />
                <add value="Default.htm" />
                <add value="index.htm" />
                <add value="iisstart.htm" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

# 二、导航失败,路由无效

# CRUD生成的菜单

# 自建的菜单规则

  1. 请检查组件路径是否正确。
  2. 后台菜单请将组件放置于/src/views/backend/目录内。
  3. 前台菜单请将组件放置于/src/views/frontend/目录内。

# 三、请求跨域错误

# 您在开发环境 (opens new window)

  1. 开发环境下,请使用localhost:1818访问站点,server端已经放行该域名,请勿使用IP访问。
  2. 无需修改web/.env.development文件,API请求地址已正确配置(除非你明白你在做什么)。

# 您在生产环境 (opens new window)

  • webserver在同一站点,不存在此问题,除非您已经独立部署web端,那么请在config/buildadmin.php文件中配置允许跨域的域名。

# 四、禁用模块时提示:ENOENT: no such file or directory, open '文件路径'

这是因为禁用模块时会自动删除模块提供的文件,文件丢失后vite报错是正常现象,请刷新浏览器继续使用即可。