How to configure php pseudo static pages
implementing pseudo static in PHP can be achieved using Apache’s URL rewrite module (mod_rewrite). One common method of pseudo static configuration is as follows:
- Make sure that the mod_rewrite module is enabled on your Apache server. You can check if it is already enabled by running the following command in the terminal.
sudo a2enmod rewrite
- Create a file named “.htaccess” in the main directory of the website (skip this step if the file already exists).
- Include the following code in the “.htaccess” file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# 将所有非真实存在的文件或目录请求重写到index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
- Save and close the “.htaccess” file.
- Make sure that the entry file of your PHP application is “index.php”. If it is not, replace “index.php” in the code above with the correct entry file.
- Restart the Apache server for the configuration changes to take effect.
sudo service apache2 restart
Now, when your PHP application receives a request for a pseudo-static URL, it will be rewritten to the “index.php” file, allowing you to parse the URL as needed in the application.