I have a problem with nginx to see if a user can help me, I can not activate pretty url in my forum smf
Restarting nginx: nginx: [emerg] unknown directive "action=$1" in /etc/nginx/sites-enabled/myweb.com:48
nginx: configuration file /etc/nginx/nginx.conf test failed
rewrite ^/profile/([^/]+)/?$ /./index.php?pretty;action=profile;user=$1 last;
rewrite ^/(activate|admin|announce|attachapprove|buddy|calendar|clock|collapse)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2|emailuser)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(findmember|groups|help|helpadmin|im|jseditor|jsmodify|jsoption)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(lock|lockvoting|login|login2|logout|markasread|mergetopics|mlist)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(moderate|modifycat|modifykarma|modifyrespetos|movetopic|movetopic2|notify|notifyboard)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(openidreturn|pm|post|post2|printpage|profile|quotefast|quickmod)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(quickmod2|recent|register|register2|reminder|removepoll|removetopic2|reporttm)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(requestmembers|restoretopic|search|search2|sendtopic|smstats|suggest|spellcheck)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(splittopics|stats|sticky|theme|topicsolved|trackip|about:mozilla|about:unknown)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(unread|unreadreplies|verificationcode|viewprofile|vote|viewquery|viewsmfile|who)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/(.xml|shop|shop|xmlhttp)/?$ /./index.php?pretty;action=$1 last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/?$ /./index.php?pretty;board=$1.0 last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ /./index.php?pretty;board=$1.$2 last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ /./index.php?pretty;board=$1;topic=$2.0 last;
rewrite ^/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ /./index.php?pretty;board=$1;topic=$2.$3 last;
Related
How to convert below condition for nginx,
RewriteEngine on
RewriteRule ^([^\.]+)/?$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)/$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)/([^\.]+)$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)/([^\.]+)/$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)$ index.php?$1 [L]
RewriteRule ^([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)/$ index.php?$1 [L]
I need to convert the apache .htaccess to Nginx configuration, if anyone knows the solution please help me, thanks.
Already I have converted .htaccess file to Nginx configuration by using some online tools, but it's not working.
If I put the URL in the browser automatically downloaded the index.php file. I have checked info.php but fpm also working fine. I don't know how to fix this issue.
here i have mention my Nginx conf file:
server {
server_name example.com;
root /home/example/public_html;
index index.php;
access_log /var/log/nginx/example/example-access.log;
error_log /var/log/nginx/example/example-error.log;
location / {
rewrite ^/([^\.]+)/?$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
}
location ~ ^/(?:\.htaccess) {
deny all;
}
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php5.6-fpm-example.com.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
The GetPageSpeed converter provides the correct result:
server {
server_name example.com;
rewrite ^/([^\.]+)/?$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)/$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 last;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 last;
}
Note the last directive. This is correct. It will make sure NGINX will start location search again to see which directives are applicable to rewritten URI /index.php. Then it finally ends up in your location ~ [^/]\.php(/|$) { ... } and directives for processing with PHP-FPM will apply.
With break, things will not work, because there's no new location search after rewriting URL. The URI stays /index.php but directives from location ~ [^/]\.php(/|$) { ... } will not be applied because NGINX didn't "go to" apply directives from it.
UPDATE 2022-03-18
As pointed out by #Danila Vershinin the rewrite statements should end with last instead of break.
You can try something like this
location / {
rewrite ^/([^\.]+)/?$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)$ /index.php?$1 break;
rewrite ^/([^\.]+)/([^\.]+)/([^\.]+)/([^\.]+)/$ /index.php?$1 break;
}
or use a converter or another converter.
I have transferred my server apache to Nginx but I face problem on our .htaccess rewrite rule
I have this rule on .htaccess
RewriteEngine On
RewriteRule ^dl/(\w+)/(\w+)/(.*)/?$ download.php?pt=$1&tk=$2&flen=$3 [L,QSA,NC]
I try this code in Nginx but not working
http{
server {
listen 80;
server_name *.oursitename.com;
location / {
rewrite ^dl/(\w+)/(\w+)/(.*)/?$ download.php?pt=$1&tk=$2&flen=$3 last;
}
}
}
I put location like location / because our download.php file in public_html main area.
please tell me how to it is working fine help me thanks
With the following rewriter:
server {
server_name example.com;
rewrite ^/dl/(\w+)/(\w+)/(.*)/?$ /download.php?pt=$1&tk=$2&flen=$3 last;
}
can anybody help me to convert .htacess file to nginx rewrite rule
my htaccess blew
RewriteEngine On
RewriteRule ^video/([^/]*)/([^/]*)\/$ /index.php?page=details&title=$1&id=$2 [L]
RewriteRule ^video/([^/]*)\.html$ /index.php?page=result&q=$1 [L]
i try apply on here:
/etc/nginx/sites-available/default
# nginx configuration
location /video {
rewrite ^/video/([^/]*)/([^/]*)\/$ /index.php?page=details&title=$1&id=$2 break;
rewrite ^/video/([^/]*)\.html$ /index.php?page=result&q=$1 break;
}
not working..
I have this Nginx rule:
location /fr {
rewrite ^/(fr)(?:/([^/]+))?$ /$2?lang=$1 last;
}
I have pages such as:
example.com/en/some-page
example.com/fr/some-page
example.com/fr
...
But I also have a page which starts by fr:
example.com/free-plan // doesn't work
example.com/fr/free-plan // doesn't work either
How can I modify my Nginx rule so that the /fr rule doesn't interference with my free-plan page?
Ps: I use PHP and rules to service page without the extension:
location / {
try_files $uri $uri.html $uri/ #extensionless-php;
}
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
I would suggest that you treat /fr as a special case and use location /fr/ to avoid side-effects from pages that begin with fr.
For example:
location = /fr {
rewrite ^/(.*)$ /?lang=$1 last;
}
location /fr/ {
...
}
See this document for details.
I am having problems creating a rewrite rule that match my .htaccess on Nginx, I am hoping someone can point me to the right direction.
My .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|app|assets|upload|api)
RewriteRule ^([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)(?:/([^/]+)|) index.php?class=$1&action=$2¶m=$3 [L]
My nginx configuration
location / {
rewrite ^/([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)(?:/([^/]+)|) /index.php?class=$1&action=$2¶m=$3 break;
}
Query params are optional for example:
site.com/
site.com/customers
site.com/customers/add
site.com/customers/edit/1
I cannot rewrite the app code since iam only migrating from apache to nginx.
Any help will be appreciated.
Thanks.
You could structure the solution like this:
root /path/to/root;
index index.php;
location / {
try_files $uri $uri/ #rewrite;
}
location #rewrite {
rewrite ^/([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)(?:/([^/]+)|) /index.php?class=$1&action=$2¶m=$3 last;
return 404;
}
location ~ \.php$ {
try_files $uri =404;
# fastcgi stuff
}
I have not checked your regular expression. The try_files directive is documented here.