How can mod_rewrite be utilized to manage subdomains and URL redirection in a PHP application?
Mod_rewrite can be utilized in a PHP application to manage subdomains and URL redirection by creating rules in the .htaccess file. This allows for custom redirection of URLs based on specific criteria, such as subdomain or query parameters.
RewriteEngine On
# Redirect all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
# Redirect subdomains to specific pages
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ subdomain.php [L]
Related Questions
- What are some resources or tools that can help beginners stay updated on the latest PHP versions and practices?
- What are the advantages of writing PHP code in English over other languages?
- What are the advantages of using NumberFormatter in PHP for currency formatting compared to manual formatting methods?