Configuring HTAccess Rewrite Rules
To set up .htaccess rewrite rules for pseudo-static content, you need to add Rewrite rules to the .htaccess file. Here are some common examples of .htaccess pseudo-static rules:
- Hide the .php extension in the URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
- Rewrite the .php extension in the URL to .html.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)\.html$ $1.php [NC,L]
- Redirecting a URL to another URL:
RewriteEngine On
RewriteRule ^old-url$ /new-url [R=301,L]
- Redirect all URLs that do not start with “www” to URLs that start with “www.”
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
- Redirect URL to HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Please choose the appropriate rules based on your needs and add them to the .htaccess file. Please note that before configuring, you need to make sure that the mod_rewrite module is enabled on the server.