phpBB rewrite rules and php parser rules conflicting on nginx - nginx

Guys I am so bad at this nginx rewrite rules. Sad thing is that nginx is sooooo lightening fast that I cannot also quit using it.
Please help me.
I have installed SEO urls on the forum.
But i am unable to control the php files and the SEO urls both together.
If i open the SEO urls then php parser stops working and i can download the php source files instead.
/forum/compare-cameras-support-f1/
BUT if i open php URLs in format below they work fine.
/forum/viewforum.php?f=1
I have spent hours trying to make both work but have just given up.
location ^~ /forum/ {
# forum will run separate
# rewrite rules for forum
rewrite ^/(.*)-f([0-9]*)/(.*)-t([0-9]*)-s([0-9]*).html /forum/viewtopic.php?f=$2&t=$4&start=$5&$query_string break;
rewrite ^/(.*)-f([0-9]*)/(.*)-t([0-9]*).html /forum/viewtopic.php?f=$2&t=$4&$query_string break;
rewrite ^/(.*)-f([0-9]*)/index-s([0-9]*).html /forum/viewforum.php?f=$2&start=$3&$query_string break;
rewrite ^/(.*)-f([0-9]*)/ /forum/viewforum.php?f=$2&$query_string break;
rewrite ^/(.*)-f([0-9]*) /forum/viewforum.php?f=$2&$query_string break;
# app rewrite rules for the INSTALLATION
#try_files $uri $uri/ /forum/install/app.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
Please help

Related

OpenCart 3 nginx config for multi language

I have a config
location / {
try_files $uri $uri/ #opencart;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
location #opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
it works fine, but I am want to add multi-language support from URL like:
location /en {
rewrite ^/en/([^?]*) /index.php?_route_=$1&lang=en break;
}
location /es {
rewrite ^/es/([^?]*) /index.php?_route_=$1&lang=es break;
}
Get language as the first URL param, and put it as get parameter &lang=es to index.php.
How correctly do that?
I don't think there is a way to do that multilingual postfix through nginx (or even apache) configs. There are a lot of connections and routing around the main HTTP_SERVER (or HTTPS_SERVER) global constant. Maximum what will you get - 301 redirect on every page loading. Which is unacceptable for search engines.
I suggest you to try tree different ways to solve this tusk:
Rewrite system/library/url.php or
catalog/controller/startup/startup.php. Don't have the exact code, but if you are familiar to php - the routing of URL you can find in
these files. Nice manual here
How to set language through url in opencart
Use some free or paid modules from marketplace by query "language code in url".
If You are using SEO URL - there are multilingual urls on each product, category etc. You don't need postfix with these, all URLs could multilingual and unique.
If you don't have these functions - just download it from here, it's free https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=32788

Removing path from urls in Nginx

My site works correctly as
https://example.com/website/page/Home
https://example.com/website/page/AboutUs
I would like to remove the /website/page part so that end users would see https://example.com/Home etc.
I read on Nginx website that rewrites are not preferred so I tried:
Location / {
try_files $uri /website/page$uri;
}
I get an internal serval error. What is the right way?
Consider using a rewrite like:
# rewrite example.com/awesome to example.com/website/page/awesome
rewrite ^(/.*) /website/page$1 break;
This should work similarly:
rewrite ^/(.*) /website/page/$1 break;

SuiteCRM REST API v8 Not working with Nginx (ubuntu 18.0)

I try to get access token Using REST API v8 but getting 404 . error.
I have change nginx conf file for rewrire rules but it's not working .
location /api {
rewrite ^/api/(.*?)$ /lib/API/public/index.php/$1 break;
}
We faced the same issue with SuiteCRM 7.11.5 configured in Ngnix. Access token cant be available on calling the API. There is some sort of redirections issues faced in suitecrm with nginx. It is to better to update your docker. server with Apache and predefined .htaccess file in directories.
This fixed our issue on 404 error in API response.
This works for me:
location ~ /Api/ {
index index.php;
try_files $uri #rewrite_api;
location ~ \.php {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
location #rewrite_api {
rewrite ^/Api/(.*)?$ /Api/index.php/$1 last;
}
In addition to the response to make it work with access token request Api/access_token
It has to look like
location #rewrite_api {
rewrite ^/Api/access_token(.*)?$ /Api/index.php/$1 last;
rewrite ^/Api/(.*)?$ /Api/index.php/$1 last;
}

nignx rewrite with or without if

I recently enabled nginx + php-fpm on our centos plesk server. Apache has been stopped and i'm looking for a way to disable it completely.
I run a wordpress site that should be getting quite a bit of traffic in the next few days (1000+ concurrent). Here is my question:
I have these two options as far as i can tell regarding wordpress permalinks with nginx
rewrite /$ /index.php break;
--or--
if (!-e $request_filename) { rewrite ^(.*)$ /index.php break; }
The first one work, and really fast at that too, but it breaks index.htlm in subdirectories, robots.txt, xml sitemap etc (404)
The second one works exactly like a want it but i get a performance hit. It takes about a sec more to start loading the page.
Any of you fine lads have any ideas as I couldn't find anything?
You should give this a read http://wiki.nginx.org/Pitfalls it answers your question in the "Check IF File Exists" section.
A much better way than using if is to use a location match and try_files
location / {
try_files $uri $uri/ /index.php?$args;
}

Please help me understand simple nginx rewrite issue for subdomain robots.txt

For my subdomain I wanted to point to a different robots.txt file. I had hoped the following code would work:
if ($host ~ subdomain) {
rewrite ^/favicon.ico$ /favicon.ico break;
rewrite ^/robots.txt$ /robots.subdomain.txt break;
rewrite ^/([^\/]*)?/?(.*)?$ /index.php?in1=$1&in2=$2&$query_string last;
}
favicon.ico works fine, all other extensions are rewritten to index.php just fine, but so is robots.txt.
I spent [wasted] a lot of time trying to solve it, which I did by adding the following line after the robots.txt rewrite.
rewrite ^/robots.subdomain.txt$ /robots.subdomain.txt break;
Can someone please help me why it only works when I add this line, also any improvements to my config would be welcomed if you see any obvious inefficiencies! Thank you.
This should be what you're looking for:
location / {
rewrite ^/robots.txt$ /robots.$host.txt; # rewrites robots.txt
try_files $uri $uri/ #php; # try_files serves statics and sends everything else
# to your front controller (index.php)
# files such as favicon.ico get served normally
}
location #php {
rewrite ^/([^\/]*)?/?(.*)?$ /index.php?in1=$1&in2=$2 last;
}
The only caveat is that your robots.txt needs to be named after the full host, so in the example above your www.domain.com needs to have a robots.www.domain.com.txt file in the document root. This seems a bit ugly, so I'd do it this way instead:
rewrite ^/robots.txt$ /$host.robots.txt;
and then you name your file www.example.com.robots.txt

Resources