Jronny
Jronny

Reputation: 2294

WordPress .htaccess rewrite to a plugin directory

So I needed to rewrite the url of site.com/plugin-page/1234 to site.com/wp-content/plugins/the-plugin/packages/1234

but for some reason the url redirects instead of just rewriting. I needed it just to rewrite, not redirect.

Here's my .htaccess code.

# 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]

    RewriteRule ^plugin-page/?(.*)$ /wp-content/plugins/the-plugin/packages/$1/index.html [L]

</IfModule>
# END WordPress

Upvotes: 0

Views: 226

Answers (1)

Prix
Prix

Reputation: 19528

The order of your rule is very important, try it this way:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^plugin-page/([0-9]+)/?$ /wp-content/plugins/the-plugin/packages/$1/index.html [NC,L]

    RewriteRule ^index/.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress

What was most likely happening is that due to your rule being last WP was trying to find it by itself within its code, resulting on a redirect instead of a internal redirect.

Also make sure that index.html and the path you're internally redirecting to, exist.

Upvotes: 1

Related Questions