URL Rewrite-php pseudo-static does not rely on. htaccess what to do

Source: Internet
Author: User
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类。

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.