Joomla SEF (moved from Apache to Nginx) - .htaccess

I have a Joomla website which I want to move from Apache server to Nginx. My website have 3 languages and all URLs begins with /en, /ua or /ru. SEF URLs are enabled and work perfectly at Apache.
Website folder have .htaccess file, where (as far as I understand) the most important directives are:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
DirectoryIndex index.php index.html
Options +FollowSymLinks
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
I used http://winginx.com/en/htaccess converter, and placed its result into /etc/nginx/site-available/domain.com file:
index index.php index.html;
autoindex off;
location / {
if ($http_host ~* "^www.domain.com$") {
rewrite ^(.*)$ http://domain.com/$1 redirect;
}
if (-e $request_filename) {
rewrite ^/(.*) /index.php;
}
}
Then I've read a manual (https://docs.joomla.org/Enabling_Search_Engine_Friendly_%28SEF%29_URLs#Nginx), but nor try_files $uri $uri/ /index.php?q=$request_uri; nor expires 1d; try_files $uri $uri/ /index.php?$args; doesn't help me.
If I try to open website in my browser using directives from previous paragraph, I've got 504 (gateway timeout) error; error.log contains next error:
*1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 176.***.**.***, server: domain.com, request: "GET /en/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "domain.com"
If I don't use this and just use my directives which was converted from .htaccess, then I've got 500 (internal server) error and error.log contains next thing:
*1 rewrite or internal redirection cycle while internally redirecting to "/ru/", client: 176.***.**.***, server: domain.com, request: "GET /ru/ HTTP/1.1", host: "domain.com"
I try to google solutions a whole day, but I think I can't handle this without help of specialist :(
Also at Joomla control panel I've found that "SEF URLs work correctly at Apache and IIS7", and there is no info about Nginx. Though at docs.joomla.org there is a solution, but it doesn't work or I do something wrong =/
Please. Help!

Related

How can I send url parameter to php file like permalink in nginx?

Recently I moved to Nginx I fixed my all WordPress sites by adding a custom script
location / {
try_files $uri $uri/ /index.php?$args;
}
But now I noticed I had a custom script in the back end folder with its own .htaccess and it stopped working now.
I was using
Options -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?x=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>
This .htaccess allows me to send https://example.com/apps/scripts/api/check_connection
trail directly into api.php file as a api.php?x=check_connection
Now In Nginx I tried
# Serves api
location /apps/scripts/api/ {
try_files $uri $uri/ /api.php?x=$args;
}
But the server is returning 404 for https://example.com/apps/scripts/api/check_connection please give me a solution to fix this.
I have no idea how Nginx configs work.
I tried https://winginx.com/en/htaccess and https://www.getpagespeed.com/apache-to-nginx to convert .htaccess to Nginx config but both websites' config does not work for me.
I will be really grateful to find the solution

htaccess rules to nginx rules

I need help with reqrite htaccess rules to NGINX rules
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
if any one could help me if those rules can be worked as NGINX rules
Try this:
location / {
try_files $uri/ /$uri.php$is_args$args;
}
You will need the PHP scripts handler location block!
location ~ \.php$ {
# fastcgi or other backend configuration here
...
}

Migration failed from htaccess to nginx configuration

I'm in process of migration from .htaccess to nginx.conf file but after migration rules doesn't work as I expected.
This is content of .htaccess that I'm gonna migrato to nginx.
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
And this is content of nginx.conf that I've migrated:
index index.php
location / {
rewrite ^(.*)$ /index.php?$1 break;
}
Please let me know what's wrong with this and how can I get nginx conf file works.
Regards. Yuming
Those .htaccess statements perform a similar function to the Nginx try_files directive.
Try:
location / {
try_files $uri $uri/ /index.php?$uri;
}
See this document for details.

.htaccess to nginx rewrite rules

I want to convert a simple .htaccess file (rules) to be used with nginx. I try to access an online tool after googleit but that website is down. So, if anyone cand help, i would appreciate. Thank you. Here is my .htaccess file:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Please, try these rules:
# Deny all files that started with dot
location ~ /\. {
deny all;
}
# Try $uri - is file, $uri/ - is dir, index.html - caching, $uri.html caching, index.php -last
location / {
try_files $uri $uri/ index.html $uri.html index.php;
}
Please, try these rules:
# nginx configuration
location ~ \.html$ {
}
location / {
if ($request_uri ~ "\..+$"){
rewrite ^/$ /index.html;
}
rewrite ^/([^.]+)$ /$1.html;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}

chive on nginx, htaccess

Hello there im trying to setup chive on nginx, can someone help me convert htaccess for it ?
Options +FollowSymLinks
IndexIgnore */*
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php?__chive_rewrite_on=1&%{QUERY_STRING}
RewriteRule ^$ index.php?__chive_rewrite_on=1&%{QUERY_STRING}
</IfModule>
In case you installed chive in a subdirectory "chive" do the following:
location /chive/ {
try_files $uri chive/$uri/ /chive/index.php?q=$uri&$args;
}
without a subdir:
location / {
# ... existing options ... check twice!
try_files $uri $uri/ /index.php?q=$uri&$args;
}
instead of $args you could use $query_string, according to http://wiki.nginx.org/HttpCoreModule (It reads: "The same as $args except that this variable is readonly.")
Great project appeared since then
https://github.com/perusio/chive-nginx

Resources