How to use mod_rewrite (Apache) nginx replacement on Plesk? Print

  • mod-rewrite, nginx, Apache
  • 76

Plesk servers running Nginx as a reverse proxy or standalone web server do not read Apache .htaccess files. To use URL rewriting, you must convert your mod_rewrite rules into Nginx syntax and add them directly to the Plesk control panel.

Step 1: Convert Apache Rules to Nginx Syntax

Nginx uses a different structure for rewriting URLs. You must translate your existing rules before adding them to Plesk. Every Nginx statement must end with a semicolon.

Apache Example:

RewriteRule ^product/([0-9]+)$ product.php?id=$1 [L]

Nginx Equivalent:

rewrite ^/product/([0-9]+)$ /product.php?id=$1 last;

Step 2: Add the Rules to Plesk

  1. Log in to your Plesk Control Panel.
  2. Navigate to Websites & Domains.
  3. Locate your domain and click on Apache & Nginx Settings.
  4. Scroll down to the section labeled Additional Nginx directives.
  5. Paste your converted Nginx rewrite rules into the text area.
  6. Click Apply or OK to save the changes and reload Nginx.

Standard Rule for Common CMS (WordPress, Drupal, Joomla)

If you are trying to enable search-engine-friendly URLs for standard content management systems, you generally do not need complex rewrite rules. Instead, paste the following block into the Additional Nginx directives box:

location / {
    try_files $uri $uri/ /index.php?$args;
}

Troubleshooting Common Issues

  • 404 Errors on Static Files: If images or CSS break, ensure that Smart static files processing is configured correctly, as Nginx will attempt to serve these files directly without passing them to Apache.
  • Nginx Restart Failures: If Plesk displays an error after saving, verify that every single line of your custom directives ends with a semicolon (;). Missing semicolons will cause syntax failures.

Was this answer helpful?

« Back