I'm running on Nginx server.

I try to rewrite my URL using .htacces file:

RewriteEngine On
RewriteBase /
RewriteRule ^search/(.+)/page=(.+)$ search-results.php?q=$1&page=$2

It give me Internal Error 500. Any help?

  • 2
    .htaccess is an Apache config file; not Nginx? – MrWhite Dec 20 '15 at 14:49

Welcome to WSE. Nginx doesn't support .htaccess and if you trying to use .htaccess with Nginx you are doing it incorrectly.

Apache's .htaccess is powerful and, as I have now learned (thanks @closetnoc), it caches the .htaccess file until it changes on the disk to avoid reloading it each and everytime. However, you wanted Nginx for it's speed didn't you, so to achieve a similar functionality with Nginx it takes a different approach, one which properly utilises the Nginx config file.

See this link for more details https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/

For further details on how to translate your .htaccess commands to Nginx, google "Converting .htaccess to Nginx"

| improve this answer | |
  • Apache currently caches the .htaccess and therefore does not access the file per request. Apache has cached the .htaccess since at least v.1 and fully implemented better caching methods by v.1.2 when it was no longer using a 5 minute cache and checking the file for changes via the modification date/time. Currently, it uses a file system trigger to reload the cache with a current version of the file only if the file changes. The .htaccess inefficiency theory has been largely a myth for a very long time. It does require reprocessing for any request that is effected however. – closetnoc Dec 21 '15 at 5:56
  • OK that makes sense, and that is very good to know, thanks @closetnoc – garth Dec 21 '15 at 10:52

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