This article mainly introduces about ThinkPHP5.0 Linux Apache/nginx rewrite URL configuration, has a certain reference value, now share to everyone, the need for friends can refer to
Author system is ubuntu,centos and other Linux distributions please change your own
PHP Framework is ThinkPHP5.0, the official document is somewhat vague, so I added a bit
Have a mistake welcome to point out at any time
You can hide the application's portal file index.php through URL rewriting, which is the configuration reference for the relevant server:
[Apache]
1. Enable the Rewrite module
2.sudo a2enmod rewrite or sudo ln-s/etc/apache2/mods-available/rewrite.load/etc/apache2/mods-enabled/rewrite.load
3. Edit the configuration file/etc/apache2/apache2.conf to find the location corresponding to your Web root directory
<directory/var/www/>options Indexes followsymlinksallowoverride Nonerequire all granted</directory>
4. Change allowoverride None to allowoverride all
5. Restart Services sudo service apache2 restart
6. Save the following content as a. htaccess file in the same sibling directory as the application portal file (created by default, if not created by yourself)
<ifmodule mod_rewrite.c>options +followsymlinks-multiviewsrewriteengine onRewriteCond%{REQUEST_FILENAME}!- Drewritecond%{request_filename}!-frewriterule ^ (. *) $ index.php?/$1 [qsa,pt,l]</ifmodule>
[Nginx]
In Nginx low version, PathInfo is not supported, but can be implemented by configuring the forwarding rules in Nginx,
Edit File/etc/nginx/sites-available/default:
server {//..... omit part of the code root/var/www/html; Locate this module and fill in the following configuration} location /{//... omit part code if (!-e $request _filename) { rewrite ^ (. *) $ / Index.php?s=/$1 last ; break; } }
In fact, the internal is forwarded to the thinkphp to provide a compatible URL, in this way, you can solve other non-support PathInfo Web server environment.
If your application is installed in a level two directory, the Nginx pseudo-static method is set as follows, where/tp5/public/is the directory name in which it resides.
location/tp5/public/{ if (!-e $request _filename) { rewrite ^/tp5/public/(. *) $ /tp5/public/ Index.php?s=/$1 last ; }}
The original Access URL:
http://serverName/index.php/module/controller/operation/[parameter name/value of parameters ...]
Once set, we can access it in the following ways:
http://serverName/module/controller/operation/[parameter name/value of parameters ...]
If you do not modify the permissions of the server, you can make changes in the index.php portal file, which is not the correct practice, and does not necessarily succeed, depending on the server, but only before the framework to complete the completion of the $_server[' path_info ' parameters
$_server[' path_info '] = $_server[' Request_uri '];
Finally restart the server
sudo service nginx restart
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!