<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp_test/
RewriteRule ^index\.php$ - [L]

RewriteRule ^the_image$ wp-content/uploads/2019/01/banner\.jpg [L]
RewriteRule ^the_page$ sample-page [L]

When I go to example.com/the_image it shows the correct image. However, if I go to example.com/the_page it shows the page not found page.

Any work around on this?

  • Not to question the obvious, but are you sure that sample-page is really there? In other words that the redirect rule might actually be working? – tmdesigned Jan 21 '19 at 3:05
  • So far no way around this. I end up customizing the plugin – ACD Mar 18 '19 at 9:53

Please make sure your permalinks are set up as /%postname%/(Post name). You can do this in the Admin by navigating to Settings > Permalinks.


Can you move those htaccess rules to be the first ones in the .htaccess file i.e. above WP default rewrite rules?


It's complicated. What you want can't easily be done that way. But your probable goal can be reached a different way.

Some background: rewriting is done in two places, and the usual configuration uses them in two different ways. First, Apache does some rewriting. The usual aim here is to separate requests that Apache can handle directly (because it just needs to respond with an existing file, e.g an image) from the ones for which WordPress should respond. The second set of rewrites occurs within WordPress, aiming to help determine what template to use.

Part of the problem with your Apache rewrites is that you're missing a rule that causes Apache to hand things over to WordPress. So 'the_image' works, because the rewrite results in a path to a file and Apache knows how to respond. But 'the_page' doesn't, because the rewrite results in something that doesn't correspond to a file, and Apache doesn't know what to do. So you need the three ending lines

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]

(note the three lines are just one rewrite rule, because the first two lines are just conditionals that affect the application of the last line.)

Now, adding those lines still gives a 'not found' message, albeit from WordPress instead of from Apache. I'm not completely sure why. There may be bug where it always looks at the request as it was before Apache re-wrote it. There may be an esoteric issue stemming from the use of PHP 7 instead of 5. It's hard to be sure, because it involves a 376-line function. In any case, WordPress ends up looking for a page called 'the_page', not 'sample-page'.

So, the workaround is to have each rewrite facility do what's more usually expected of it. In particular, have WordPress handle the rewrite for 'the_page'. There are several filters where you can easily tweak WordPress's rewrite rules. I can add detail if you need it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.