nginx rewrite wp default /?page_id=10 to /my-cool-page - wordpress

I've got a friend whose WP site is using the default /?page_id=xx permalink structure. I have been trying to create a nginx rewrite to convert the links to a post_name scheme.
There are dozens of pages that need to be redirected so I added a file (snippets/rewrite.conf ) to handle the rewrites and included it in my nginx.conf file:
When I have the permalinks set to post_name, this works (indicating that rewrite is enabled):
rewrite https://example.com/features https://example.com/my-cool-page permanent;
I've tried every which way to make this work for /?page_id=xx permalink structure but it doesn't want to redirect.
When I have the permalinks set to default, this doesn't work:
rewrite ^/?page_id=45 /?page_id=60 permanent;
I've been googling for hours and I just can't find a solution. What is the correct way to form the rewrite.
Ubuntu 16.04
Nginx 1.10.0
MariaDB 10.1.14
PHP 7.0.4

Related

Wordpress and Laravel working together on NGINX

I'm trying to set up nginx vhost so I can use wordpress and laravel on the same domain.
I put wordpress in the root folder
And in a subfolder /laravel/ installed laravel
Is it possible to make that if for example laravel route /laravel-page in URL, request on server will not go to wordpress /index.php but to Laravel /laravel/public/index.php,
and all other pages are normally requested to /index.php
I would like to whitelist URLs using RegExp, which will be handled by Laravel.
UPDATE:
After a few experiments, I managed to get what I wanted. I added:
location ~ ^/laravel-page(?:/(.*))?$ {
index /laravel/public/index.php;
}
These pages are now handled by Laravel: /laravel-page/1333/. But for some reason, if I enter the address without the slash /laravel-page/1333 , it gives a 404 error, and not from wordpress or laravel, but the usual one from nginx. I tried adding a redirect:
rewrite ^/(.*)/$ /$1 permanent;
It works, but laravel doesn't open.

Wordpress - How to create redirection in NGINX?

I have a dilemma. I migrated my wordpress site from Apapache server to NGINX.
In the process I changed permalink in WP from
/index.php/%postname%/
to
/%postname%/
Now, users coming to site from Google, are getting 404's because of the permalink change. Typically I would just redirect any page via WP plugin, but because of this index.php in the permalink, plugins don't work. So I have no choice but to create a redirection somewhere in NGINX conf file.
Please advise what to do.
server {
rewrite ^/index.php/(.*)$ /$1 permanent;
...
}
In the server configuration file (the file will be located at /etc/nginx/nginx.conf).
If it does not exist there, it may also be at /usr/local/nginx/conf/nginx.conf or /usr/local/etc/nginx/nginx.conf.
For temporary redirect:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation redirect;
For permanent redirect:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation permanent;

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.

PrestaShop - Can't access Admin Panel on nginx

I've tried the same installation of PrestaShop (ver 1.7.5.1) with Apache and nginx (copying the nginx installation into Apache root dir).
When I surf on admin panel I see urls like this:
http://localhost/admin825pqjv9z/index.php/configure/advanced/system-information/?_token=lJz8rH0rLWJJsrgY6tC97KuCrniEs2eps41UEoU5vqY
where index.php is concatenated with the rest of the url
When I use Apache every work fine however with Nginx, I'm getting redirected.
I've tried the following nginx configuration for PrestaShop:
https://gist.github.com/vicobits/86804fa5f6bd9e2a38f353518563590f
but it did not worked.
I just tried the example you provided on my nginx install and it went well.
Did you replace /admin-dev/ by your own admin folder name /admin825pqjv9z/? You should have:
location /admin825pqjv9z/ { # Change this for your admin url
if (!-e $request_filename) {
rewrite ^/.*$ /admin825pqjv9z/index.php last;
}
}
I hope this helps, otherwise I'd be happy to check other options with you.

Convert these rewrite apache rules to nginx

In my Wordpress, I changed the posts permalinks structure. In order to don't get 404 erros for the old links, I would like to redirect the old permalinks to the new permalinks. According to this, the following code must be added in my .htacess so that I can get the redirect working from old posts links to the new posts link:
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ http://myurl.com/$3
That's good, however, I don't use Apache – I use nginx. How can I convert this rules to nginx? I've already tried a apache to nginx online converter, with no success.
Thanks!
I believe this is what you want. "permanent" is 301 according to this page.
rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+).html$" http://myurl.com/$3 permanent;

Resources