PHP website address URL redirection
Website URL redirection is usually used during Website construction.The advantage is that it is conducive to SEO optimization on your website, that is, to make your website pseudo-static. The following describes the two methods:
1. set redirection in the Apache configuration file
First, find the Apache configuration file httpd. conf, find the following code LoadModule rewrite_module modules/mod_rewrite.so in the configuration file, and open it (that is, remove the previous ).
Then open the output phpinfo () function. if the mod_rewrite module is enabled in the module, the above step is successful, as shown in figure
Then configure the URL rules. if you have not configured the Apache virtual host, read the following article.
Wamp development environment configuration-Apache virtual host configuration
Locate the file httpd-vhosts.conf for Apache to configure the VM and write under the tag
RewriteEngine on
RewriteBase/
RewriteRule index. php test. php
Note: (1) which virtual host do you want to configureURL redirectionIt is written under the virtual host label.
(2) RewriteBase refers to the directory of your test. php file,/indicates the root directory of the website. if you test. php is in the folder, write//
(3) RewriteRule indicates the matching rule. This indicates that when the user enters the index. php page, the user automatically jumps to the test. php page, but the URL indicates index. php.
2. Pass. HtaccessFile implementationURL redirection
The first step is to open the mod_rewrite module. The second step is to find the tag in the Apache configuration file and change AllowOverride None to AllowOverride All under this tag.
Create a. htaccess file (tell you secretly, read H-T-access, don't thank me). Because window does not allow files without file names, we can do this.Create a. htaccess file
Open Notepad, click save,Note that the encoding is ANSI. sometimes the. htaccess file is invalid because the file encoding is incorrect.
The following code is written in the. htaccess file. the content is the same as the content in the first method.
3,URL redirectionNotes
First, for example, if you want to redirect index/, blog/to index. php, blog. php, you can write
Then, when we define. after the rules in htaccess, you need to note that the paths of js, css, and image on the original website may fail, because the address of your website is index, the browser will think that in the index folder, all of you will find your css, js, and image in the index folder, and all of them will go wrong. The solution is to use the absolute path, that is, add a/symbol before your path to start searching for this file from the root directory of the website!