The presence of index.php in your WordPress URLs usually indicates that your site is not using a proper permalink structure or your server configuration does not support “pretty permalinks.” Here’s how you can remove it:
1. Check and Update Permalink Settings
- Log in to your WordPress admin dashboard.
- Go to Settings > Permalinks.
- Select a permalink structure other than Plain (e.g., “Post Name” or “Custom Structure”).
- Click Save Changes.
If the
index.phpstill appears in your URLs after this, continue with the following steps.
2. Ensure .htaccess File Exists and is Configured Correctly
- Locate the
.htaccessfile in your WordPress installation’s root directory (via FTP or File Manager in your hosting panel). - Ensure it contains the following standard WordPress rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
- If the file is missing or does not include these rules, add them and save the file.
Note: Ensure the file is not hidden in your file manager.
.htaccessfiles are often hidden by default.
3. Verify Apache’s mod_rewrite Module is Enabled
- WordPress relies on the
mod_rewritemodule for pretty permalinks. - If you have access to your server (via SSH or cPanel), ensure this module is enabled.
- For cPanel:
- Go to Apache Configuration > Global Configuration and enable
mod_rewrite.
- Go to Apache Configuration > Global Configuration and enable
- For Ubuntu-based servers:
sudo a2enmod rewrite sudo systemctl restart apache2
4. Adjust Server Configuration
If you are on shared hosting and cannot enable mod_rewrite yourself, contact your hosting provider and request it be enabled.
5. Custom Rewrite Rules for Nginx
If your site is running on Nginx (not Apache), .htaccess files won’t work. Instead, add the following rules to your server block configuration:
location / {
try_files $uri $uri/ /index.php?$args;
}
Then restart Nginx:
sudo service nginx restart
6. Check for Plugin or Theme Conflicts
- Some plugins or themes may enforce the use of
index.phpin URLs. - Deactivate all plugins and switch to a default WordPress theme (e.g., Twenty Twenty-Three) to test if the issue persists.
- Reactivate plugins/themes one by one to identify the culprit.
7. Review WordPress Configuration File
- Ensure your WordPress Address and Site Address are correctly set in Settings > General:
- They should look like:
https://yourdomain.com(without/index.php).
- They should look like:
- If you cannot update it via the admin panel, check the
wp-config.phpfile for any forced settings:
define('WP_HOME', 'https://yourdomain.com');
define('WP_SITEURL', 'https://yourdomain.com');
After completing these steps, the index.php should no longer appear in your URLs. If you still encounter issues, your hosting provider might need to assist in resolving server-related configurations.