Score:1

How do I convert this .htaccess snippet to Nginx rules?

pk flag

I have this snippet of .htaccess coming from Apache:

RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteCond %{DOCUMENT_ROOT}/u_pages/%1.php -f
RewriteRule .* u_pages/%1.php? [L]

Using the Winginx online converter I get the following:

location / {
  if ($request_filename ~ index\.php){
    rewrite ^(.*)$ /u_pages/%1.php? break;
  }
}

But that doesn't seem to do anything.

What I'm trying to achieve:

I have regular plain php-documents in the folder /u_pages/ -- e.g. 123.php, 444.php etc.

I need each of these to have URLs on the following basis:

example.com/index.php?id=123

-where the file name (123.php) corresponds with the number after id= in the URL

Hoping someone can lend a hand. Thanks very much in advance.

djdomi avatar
za flag
which software is beeing used?
pk flag
Thank you!! No software for these pages, they are just static pages. However, there is a Wordpress install on the domain as well, but it's not being used to display these pages. Can you help?
djdomi avatar
za flag
a php file is not static. So what are you trying to do? It looks for me like an enduser ehich in fwct would be not on topic for serverfault.com but may be asked on superuser.com or webmasters
pk flag
Disregard the file extension -- might as well be .html -- still trying to rewrite the URLs on Nginx.
djdomi avatar
za flag
have you seen https://stackoverflow.com/questions/5840497/convert-htaccess-to-nginx
pk flag
I've tried the online converter, if that's what you mean. Didn't work.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.