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.