假设当前服务器上只有一个 index.php 文件。 当访问: http://xxx.com ,能直接访问到 index.php ,没问题 但是访问: http://xxx.com/abc,会提示找不到网页。 有没有什么办法(做配置?特殊代码?)使访问上述带路径的网址时,访问的是 index.php ,然后在 index.php 里面获取到这个 abc 参数?
1 troycode 2020-02-21 15:48:30 +08:00 这应该是设置的解析路径把,url 包含入口文件 |
![]() | 2 azoon 2020-02-21 15:51:49 +08:00 1.配置 rewrite 2.$_SERVE['PHP_SELF'] 随便找个 PHP MVC 框架看看吧 |
![]() | 3 R18 2020-02-21 15:51:50 +08:00 via Android 伪静态 |
![]() | 4 KasuganoSoras 2020-02-21 15:57:44 +08:00 如果网站服务器是 Nginx,可以这样做伪静态规则,将所有请求转发到 PHP 上: location / { rewrite ^ /index.php$uri; } 然后 PHP 里这样写就可以获取请求的完整地址: echo $_SERVER['REQUEST_URI']; |
![]() | 5 encro 2020-02-21 16:00:40 +08:00 |
6 xFrank OP xampp 下怎么配置? |
![]() | 7 U7Q5tLAex2FI0o0g 2020-02-21 16:03:35 +08:00 路由 |
8 xFrank OP |
![]() | 9 jswh 2020-02-21 16:16:23 +08:00 # 访问: http://xxx.com/abc,会提示找不到网页。 有没有什么办法(做配置?特殊代码?) 这个实在 http server 上做的,nginx/apache,软件不同配置方式不同,建议自己学习相关知识 # 然后在 index.php 里面获取到这个 abc 参数? PHP 的外部系统相关参数都在$_SERVER 这个全局变量里面,类似$_GET 和$_POST,自己找。 |
![]() | 10 580a388da131 2020-02-21 16:26:55 +08:00 |
![]() | 11 KasuganoSoras 2020-02-21 16:27:17 +08:00 @xFrank #6 Apache 我不会配置,你可以搜索一下 “Apache 伪静态” |
![]() | 12 FragmentLs 2020-02-21 16:58:14 +08:00 .htaccess RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /index.php [L,QSA] |
![]() | 13 Nekonico 2020-02-21 17:20:26 +08:00 @xFrank 阿帕奇配置如下 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php/$1 [L] @KasuganoSoras 哈哈小樱~ |