PHP removes the indexphp in the URL

Source: Internet
Author: User
PHP project, in order to access the friendship of links and SEO optimization, we often need to configure a short link to visit the page, and the index.php removed.
The Web server used by PHP is usually: Nginx or Apache. Let's talk about the different configuration methods of the two kinds of servers separately

NGINX configuration:
1. Open nginx configuration file:/usr/local/nginx/conf/nginx.conf
2, modify the file, there are two kinds of syntax
A:

location / {     $uri$uri/ /index.php?q=$uri&$args;}

B:

location / {       if (!-e$request_filename) {            rewrite ^/(.*)$  /index.php?q=$uri&$args;       }}

If the root directory is a level two directory, you need to make the corresponding modifications:
A:

location /cn/ {          $uri$uri/ /cn/index.php?q=$uri&$args;  }

B:

location /cn/ {       if (!-$request_filename) {             rewrite ^/cn/(.*)$  /cn/index.php?q=$uri&$args;       }}

3, check Nginx syntax error, no error restart

#检查是否有语法错误/usr/local/nginx/sbin/nginx -t#重启nginx/usr/local/nginx/sbin/nginx -s reload

Apache configuration:
1. The mod_rewrite.so module is loaded in the httpd.conf configuration file

#LoadModule rewrite_module modules/mod_rewrite.so   # 去掉

2. Modify the httpd.conf configuration file:
allowoverride None Change None to all
(Note that the allowoverride in other places are all set to all)

AllowOverride none  改   ALLOptions None    Order allow,deny    Allowall

3.. htaccess files must be placed in the following directory
. htaccess file Contents

RewriteEngineonRewriteCond%{REQUEST_FILENAME} !-dRewriteCond%{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP removal URL in the indexphp, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.