🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## apache 伪静态 在public下新建.htaccess文件,复制以下代码。注意:public目录下是自带该文件的。 ~~~ <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] </IfModule> ~~~ ## nginx 伪静态 参考 1. 宝塔服务器参考[Linux下宝塔安装](Linux%E4%B8%8B%E5%AE%9D%E5%A1%94%E5%AE%89%E8%A3%85.md) 找到nginx网站配置文件,打开后在合适位置增加以下配置 ``` #伪静态配置,重写规则引用,修改后将导致伪静态规则失效 location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } ``` 完整nginx配置参考 ~~~ server { listen 80; server_name 192.168.0.118; index index.php index.html; root /www/data/HkCms/public; #PHP引用配置 location ~ [^/]\.php(/|$) { try_files $uri =404; # Socket管道方式 # fastcgi_pass unix:/tmp/php-cgi-71.sock; # tcpip方式, 端口根据PHP-FPM配置文件 fastcgi_pass 127.0.0.1:10711; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_index index.php; # 引用fastcgi_param参数 include fastcgi.conf; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } #伪静态配置,重写规则引用,修改后将导致伪静态规则失效 location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } #禁止用户上传目录下所有.php文件的访问,提高安全性 location ~ ^/uploads/.*\.(php|php5)$ { deny all; } #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; error_log /dev/null; access_log off; } location ~ .*\.(js|css)?$ { expires 12h; error_log /dev/null; access_log off; } # 访问日志 access_log /www/wwwlogs/192.168.0.118.log; # 错误日志 error_log /www/wwwlogs/192.168.0.118.error.log; } ~~~ ## IIS参考 主要添加的内容 ``` <rewrite> <rules> <rule name="OrgPage" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> ``` 添加的位置 ``` <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="OrgPage" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> <handlers> </handlers> </system.webServer> </configuration> ```