If you have a third-party framework to do the project, the URL path can be the same way as the framework to set the method (such as thinkphp), but if the use of native PHP write projects and want to rewrite the URL, you can have some Apache settings to achieve the desired effect.
Before you change the configuration of Apache, you should be aware of some Apache knowledge: The role of the directory tag in Apache is to mark the behavior of how we customize Apache in a particular directory. The tag will have an absolute path, which is the directory where you want to customize the behavior.
In general, the idea of modifying URLs through Apache is to rewrite the URL addresses you want to rewrite in the. htaccess text. The steps are as follows:
(1) Now in the server's httpd.conf file, open the override. htaccess permission to add the following code to the httpd.conf file
<directory ". htaccess file Path" >
AllowOverride All
</Directory>
(2) where the. htaccess file is stored: If your previous access path is: Domain name/car_project/index.php
Obviously, this path accesses the index.php file in the Car_project folder, so if you want to rewrite the path, you should put the. htaccess file in the Car_project folder.
(3) then the. htaccess file will be opened with the rewrite engine inside, add the following code in the. htaccess file
<ifmodule mod_rewrite.c>
Rewriteengine on
</IfModule>
(4) Then we need to set the "redirect matching URL base address to apply" in the ifmodule tag, the instruction is rewritebase, the example is as follows:
rewritebase/demo/
And the address we're using now is: http://localhost/demo/
(5) After writing the rewriterule instruction in the ifmodule tag, the URL can be rewritten, for example by adding the following code to the tag:
Rewriterule somepage.php otherpage.php
This represents anyone accessing the somepage.php page, which is actually showing the otherpage.php page
Similarly, we can also use regular expressions to override the way the URL parameters are entered (in this case the regular expression is not unfolded in detail)
(6) So, now the httpd.conf file and the. htaccess file should have the following instance code:
In the httpd.conf file:
<directory ". htaccess file Absolute path" >
AllowOverride All
</Directory>
. htaccess file:
<ifmodule mod_rewrite.c>
Rewriteengine on
rewritebase/demo/
Rewriterule somepage.php otherpage.php
</IfModule>
Rewrite URLs in Apache using the Mod_rewrite module