Title, PHP pseudo-static does not rely on. htaccess what to do, is pure PHP can write?
Reply content:
Title, PHP pseudo-static does not rely on. htaccess what to do, is pure PHP can write?
PHP can only handle PHP requests, such as/post/1024 request, if Apache or nginx does not rewrite rewrite to pass the URI information to the specified PHP file, then PHP will not be able to pass $_server[' Request_uri ' Access to this information. If you are using PHP's built-in CLI HTTP Server, you can route and specify the route file at startup, such as index.php:
Https://wiki.php.net/rfc/builtinwebserver
Php-s 127.0.0.1:8080-t/www/www/index.php
上面这段PHP代码跟下面常用的采用index.php作为前端控制器(路由)的框架重写规则含义相近:
# ApacheRewriteEngine OnRewriteBase /RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [QSA,L]# Nginxlocation / { try_files $uri $uri/ /index.php?$args;}
你可以在每个需要重写的目录里面新建一个index.php.处理内容进行转发。
比如 要转发的地址 http://xxx.xxx.xxx/dirA/dirC/
在dirA中写一个index.php,手动转发给目的地。
PHP很多框架都有路由功能,会把url按照"/"拆分,解析出控制器、方法、参数,然后框架的控制程序就会调用对应的控制器的相应方法,并把参数传递过去。 当然参数多的时候只保持控制器和方法以目录分隔,其他参数还是能够以查询字符串的形式传递过去的。 可以看下CI框架的Router类。