Home  >  Article  >  Backend Development  >  Configuring .htaccess single point of entry_PHP tutorial

Configuring .htaccess single point of entry_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:121047browse

First enable the mod_rewrite module (adjust according to different operating systems, currently Linux)
1. Apache enables Mod_rewrite module

Edit: /etc/apache2/httpd.conf
Uncomment: LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

2. Select Directory and change AllowOverride None to AllowOverride All.

3. Restart Apache

Create a file .htaccess in the project root directory and redirect the request to the public directory (adjust as needed)
1
2 RewriteEngine on
3 RewriteRule ^$ public/ [L]
4 RewriteRule (.*) public/$1 [L]
5


Finally, forward the request to the public/index.php file, (distribute all requests here)

1
2 RewriteEngineOn
3
4 RewriteCond %{REQUEST_FILENAME} !-f
5 RewriteCond %{REQUEST_FILENAME} !-d
6
7 RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
8
9


app->public->index.php
This can achieve a single entrance to a website and is also the starting point of the MVC model. The next step can be to try to distribute our url as three parts controller/action/querystring.....


Excerpted from warcraft

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478226.htmlTechArticleFirst enable the mod_rewrite module (adjust according to different operating systems, currently Linux) 1. Apache enables Mod_rewrite module editing: / etc/apache2/httpd.conf Uncomment: LoadModule rewrit...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn