so with apache i have a folder:
www.domain.com/folder/folder1/index.php?word=blahblah
and i want users who access www.domain.com/folder/folder1/blahblah to be redirected to the above URL without the url changing.
Thus i have the following .htaccess in the folder/folder1/ which works perfectly:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?word=$1
So i want to achieve the same functionality with nginx and i used two converters: http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ results in:
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.+)$ /index.php?word=$1;
}
and http://winginx.com/htaccess results in:
if (!-e $request_filename){ rewrite ^(.+)$ /index.php?word=$1; }
now, i tried with both but neither works. I tried inserting them either in
location / {
}
or in
location /folder/folder1 {
}
or in
location ~ \.php$ {
}
in all locations i get a 404 error
nginx error reports either "primary script unknown while reading response header from upstream" or "no such file or directory".
can someone enlighten me please ?
thanks in advance!
First, don't use if
. If is evil -> http://wiki.nginx.org/IfIsEvil
You can accomplish this by using the following rewrite rule.
rewrite ^/folder/folder1/(.*)$ /folder/folder1/index.php?word=$1 last;
Place this rewrite rule just above you location / {}
block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With