Enable PHP Pseudo-Static URLs: .htaccess Guide
Enabling pseudo-static in a PHP website can be achieved by modifying the website’s .htaccess file.
Here is a commonly used method:
- Firstly, make sure your website is running on a server that supports .htaccess files, such as an Apache server.
- Locate the root directory of your website, which is typically the public_html or www directory.
- Create a file named .htaccess in the root directory (skip this step if it already exists).
- Open the .htaccess file and add the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The purpose of the above code is to redirect all requests to be handled by the index.php file, without displaying the file path and parameters.
- Save and close the .htaccess file.
- When revisiting your website, the URL should now be displayed in a pseudo-static form.
Please note that the above is just one common method, and the specific configurations may vary depending on the server environment and website structure. If you are unfamiliar with the .htaccess file or encounter any issues, it is recommended to consult your server provider or developer.