Hide a virtual folder in nginx - nginx

I'm adjusting a brand new thirty bees installation (a prestashop fork) with several languages.
Problem: my domain is ".es" (like mydomain.es), and default language is Spanish. So, when a Spanish user load the page, in the url appears something like mydomain.es /es/.
I'm trying to "hide" the "/es/" alias (or virtual folder, whatever is called), so Spanish users can see mydomain.es/product-name instead of mydomain.es**/es/product-name, but language still appears with other languages, like mydomain.es/en/**product-name
So far, I've tried this:
location = /es/ {
rewrite ^/es/(.*)$ /index.php last;
}
And this:
rewrite ^/es/(.*)$ $1 last;
But nothing works, still appears /es/ folder.
Could anyone help me?
Thank you!
PS: For detailed info, here's my nginx vhost config

Try this :
location / {
rewrite ^(.*)$ /es/$1;
}

Related

nginx - Rewrite URL Parameter to Path

So we ran into an SEO issue with a WPML after changing from using URL parameters to specify the site language to using the path. The web server is running nginx.
Before:
example.com/?lang=fr
example.com/example-path/?lang=fr
After:
example.com/fr/
example.com/fr/example-path/
So what I'm trying to do is redirect any URL following the old URL format, including the root / to the new format. This process should strip all URI parameters in the URL and replace it with the corresponding path.
I reached out to the guys over at WPML and they don't know how to do it.
I've tried two different ways:
location = / {
if ($args ~ "^lang=(fr)") {
set $key1 $1;
rewrite ^.*$ /fr last;
}
}
As well as:
rewrite ^/.*\?lang\=fr$ /index.php? permanent;
But unfortunately from what I can tell, neither of these seem to do anything. I'm really familiar with regex but for some reason I'm having a hard time with these nginx rewrites.
I was surprised that there are very few examples in the nginx docs and on google about rewriting URL parameters. Any ideas on how this could be done?
Thanks!

WP migration from apache to nginx results -- 404 -- on https

That was kind of a loaded title.
I moved my site over from Apache to Nginx and I'm learning the hard way that Nginx does things its own ways. It does not like htaccess files, ignores them. This causes problems when running Wordpress, because wordpress supposedly loves to use htaccess files and nginx does not. Why? I have no idea.
Anyways,
I managed to figure out how to bring back the site from the abyss of 404, by placing this code in nginx.conf file
location / {
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
But.
while pages load fine on HTTP, HTTPS still shows dreaded 404. Why? I don't know. So, anybody know what to do next?
Well, it turns out I also have to add the same code on nginx.ssl.conf file.
Why? I don't know, but it works.

Nginx rewrite : how to remove everything after extension of a file

There are a lot of bad request of images and files on my site... but with names close from the real name. basically, if i have a file called example.gif, there is a call to example.gifzerzer. What i want is to rewrite to keep the name and the extension, but nothing after it.
I did create a map file with rewrite (it's working for example the tmp.php to index.php rewrite below except the rule for removing everything after extension).
Here is what i've done so far :
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1;
this is not working neither
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+? /$1;
my map :
map $request_uri $redirect_uri {
default "";
/(.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1;
/tmp.php /index.php;
}
i was under Apache before migrating to Nginx and this was working :
RewriteRule ^([a-z0-9\-/_]*\.(bmp|gif|ico|jpeg|jpg|png|svg)).+ /$1 [R=301,L]
I did that rewrite that is working, when put in the server section, but then it is not included in the map.
location ~ (.+\.(bmp|gif|ico|jpeg|jpg|png|svg)).+$ {
return 301 /$1;
}
if someone has an idea why, or can confirm that i'm doing it right ?

Only homepage loads following migration (WordPress, nginx)

following a migration from a shared platform to a private cloud server only the home page is loading.
After looking around the most common fix appears to be flushing the perma links and modifying the .htaccess with the following:
AllowOverride All
However the server uses nginx, after trying a .htaccess to nginx converter with the following code added to nginx.conf:
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
}
However I had no luck with this.
Any assistance is appreciated - I hope this is sufficient information but let me know if not.
Thank you.
Rename .htaccess to some other name, lets say .htaccess1, then go to Settings -> Permalinks, Select Post Name and hit save. It will generate new .htaccess and see if it fix the issue.

Nginx 301 Redirect for folders

I am moving to a new site and the folder path has slightly changed.
Old Path: /forms/somepdf.pdf
New Path: /uploads/forms/somepdf.pdf
Note that there are sub folders in the forms folder that contain pdf documents as well. I also have an html page in /forms. So normally this would work:
rewrite ^/(forms.*) /uploads/$1 permanent;
But this makes my forms html page error 404. So, I only want to do the redirect if the filename ends with .pdf and the requested URL starts with "/forms". This is what I have so far, but it is not quite working:
rewrite ^/(forms.*)\.pdf /uploads/$1/\.pdf last;
Actually, I played with it a little more and this seems to work:
rewrite ^/(forms.*)\.pdf /uploads/$1.pdf permanent;
If you have a better solution please let me know. Thanks

Resources