Implementing WordPress Pseudo-Static for AMH Secondary Directory

Publish: 2014-10-20 | Modify: 2014-10-20

AMH4.2 virtual host panel uses nginx server. After installing AMRewrite-1.0 rewrite module, it can achieve pseudo-static for the main domain. However, some users may want to achieve pseudo-static for subdomains or subdirectories, which cannot be achieved by the default pseudo-static rules.

For example, if www.xiaoz.me has already achieved pseudo-static, and I want to install another WordPress or other programs in the wordpress directory (e.g., www.xiaoz.me/wordpress), the default pseudo-static rules will not be inherited. We need to introduce new rules to achieve it.

  1. Create a new rewrite rule, copy the following rules and save as wp2.conf:

    location /wordpress/ { 
    if (-f $request_filename/index.html){ 
    rewrite (.*) $1/index.html break; 
    } 
    if (-f $request_filename/index.php){ 
    rewrite (.*) $1/index.php; 
    } 
    if (!-f $request_filename){ 
    rewrite (.*) /wordpress/index.php; 
    } 
    }
  2. Pay attention to the wordpress directory above, assuming your subdirectory is "blog", modify the above two instances to "blog".

  3. Put the created wp2.conf into the server's /usr/local/nginx/conf/rewrite directory.

  4. Open the /usr/local/nginx/conf/vhost directory, find the website's configuration file, such as xiaoz.me.conf, and include the newly added wp2.conf file in the server{} section: include rewrite/wp2.conf; Save and overwrite it. If you are worried about making mistakes, it is recommended to backup first.

  5. Finally, restart the nginx server with the command: amh nginx restart.

This method is not only applicable to the AMH panel, but also to any users using nginx servers. The principle is the same. Everyone can try it. If you have any questions, you can add me on QQ: 337003006.


Comments