Trying to rewrite URLs for wordpress / nginx / WPML install - wordpress

I have some wordpress experience, but it's my first time using Nginx. I have a WordPress installation running on Nginx. I added WPML (multi-language plugin) https://wpml.org/
The current URL structure is https://www.maindomain.com/blog/es/.... & https://www.maindomain.com/blog/en/.... etc. Everything works fine.
I'm looking for a way to rewrite the URLs in ninginx conf for the whole set-up to work with: https://www.maindomain/es/blog/.... instead of https://www.maindomain.com/blog/es/ and so on.
I tried several things and eventually i got stuck on:
rewrite ^/blog/en/(\w+\.?.*)$ /en/blog/$1 last;
which gives a 404 error on both URLs.
Any ideas on how to do this? Or is there a better way of doing this other than with rewrites?

...is there a better way of doing this
Possibly, yes. You can install WordPress in a root directory instead of a subdirectory (/blog) or point the domain to the subdirectory. This will give you URLs like maindomain.com
You can then set the Language URL setting in WPML to "Different languages in directories". This will give you URLs like maindomain.com/es/. Finally, you can create a page with the blog slug in WordPress (you should be able to set the same slug for the translation) and it will be accessible at maindomain.com/blog or maindomain.com/es/blog.

Related

Make WordPress' default posts go to /blog -- permalinks not working

Consider the following post types
Posts (default in WordPress)
Accessories (Custom post type)
I want posts to go to /blog. Accessories slug has been defined as /accessories.
To achieve this, in settings > permalinks > and have defined my custom structure as /blog/%postname%/.
With this, when I go to /blog/, I get a 404. However, when I create a post in posts, the permalink shows up as /blog/test-title.
Also, with the custom structure set, when I try and go to /accessories, it also 404's.
Questions:
Why does /blog 404? It should use index.php as it's template, no?
Why does /accessories 404 with this change?
How do I get /blog and /accessories working?
To get this WordPress permalink stuff to work correctly, the underlying apache web server grabs the incoming URL requests and rewrites them underneath the covers so they point to /index.php?something=something. For this to work, apache must
have an extension module called mod_rewrite enabled,
be configured to allow rewriting in your WordPress instance, and
be able to write a file called .htaccess in the same folder as your WordPress index.php.
You didn't mention what kind of OS your server lives on, so it's difficult to give you specific advice. You might check Digital Ocean's fabulous documentation for help.

WordPress domain redirection

Beginner question:
I need to perform a 301 redirect from one Wordpress site (domain), to another Wordpress domain, like this:
From:
http://mycompany.com
To:
http://mycompany.se
A problem is that I have no FTP credentials for my From-site. I can't reach the .htaccess file.
Is there a plugin to use? I have studied the Redirection plugin, but this one seems working on pages within the same domain only(?)
I guess I need to be careful, because if some plugin edits the .htaccess file and something breaks, I can't reach the file...
Thankful for any help!
Whit Redirection Plugin you can redirect a url from old to new website.
You can create and manage redirects quickly and easily without needing Apache or Nginx knowledge. If your WordPress supports permalinks then you can use Redirection to redirect any URL.
There is full support for regular expressions so you can create redirect patterns to match any number of URLs.
The plugin can also be configured to monitor when post or page permalinks are changed and automatically create a redirect to the new URL.
You can easily find multiple plugins to perform 301 redirection in wordpress,but if you want to edit .htaccess you can install the plugin called "WP htaccess control" https://wordpress.org/plugins/wp-htaccess-control/ .
Through this plugin you can edit the .hraccess file from admin side.
Thanks.

Rewrite wordpress url to subdomain

i have a wordpress site let just call it testing.com
with a page url called blog/ which can access via testing.com/blog
i am using NGINX as the web server.
How do i rewrite the testing.com/blog to blog.testing.com with all its content still intact?
//edit
in this case, /blog is a page in the wordpress and not the wordpress itself, only that page and all the link inside the page would be rewrite to the subdomain and nothing else
example:
inside of the blog.testing.com there was 2 more link such as:
1. older post
(original link will be testing.com/blog/page/2 and change it to blog.testing.com/page/2)
1. read more on each post
(original link will be testing.com/2017/05/testpost1 and change it to blog.testing.com/2017/05/testpost1)
//end of edit
so as to say as if i am opening testing.com/blog in blog.testing.com
i have tried rewrite and proxy pass
location ^~ /blog/ {
rewrite ^/admin(.*) http://blog.testing.com$uri permanent;
}
with the above block
the result is same as return the url only and not with the supposed content.
or is it not possible to do so?
Hi assuming that you don't want to keep the URL testing.com/blog at all and instead want to use the subdomain blog.testing.com then effectively what you want to achieve is a WordPress migration. There are a number of ways you can achieve a migration, depending on how technically able you are. The easiest way is probably to install and use a WordPress migration plug in such as WordPress Duplicator or WordPress Move. Please take a backup of your files AND database before you start.
The official WordPress guide to migration can be found at https://codex.wordpress.org/Moving_WordPress
In short you would create the subdomain, then move (migrate) the site that's currently at testing.com/blog to the subdomain blog.testing.com
If the subdomain directory is to be left at /blog and you are just pointing the subdomain to that directory, then you might be able to do what you need to do just by updating the database to reset all the internal URLs in the WordPress database. In this case you could consider using https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
This is what I tend to use when migrating sites from test to live. Hope this helps.

WordPress Inside Magento URL Rewrite Method Issue

This may look like already submitted question. But sure it's not. Before getting into what I need, I tried these ways which found on stack,
.htaccess Method
vhost Method
Apache Config Method
Combining with all above or using individual specified methods. But I couldn't get my requirement. So only I posted this question and here my question.
I have my site like this, magento in root directory and wordpress as wp and the folder structure like this,
app/
downloader/
errors/
....
var/
....
wp/
....
index.php
....
Now I can access magento and wordpress like this
www.store-url.com - Magento
www.store-url.com/wp/blog/ - Wordpress
But I need to access like this.
www.store-url.com - Magento
www.store-url.com/blog/ - Wordpress
So far the solutions I found works correctly upto the /blog/ but anything after that is not working for me, Like,
www.store-url.com/blog/any-identifier-here/
www.store-url.com/blog/any-identifier-here/identifier-2-here/
doesn't works for me. I am looking for best rewrite option that enables me to work like above url.
I tried the below but not working,
.htaccess - Wordpress under Magento site with multi language sub directories
htaccess multi language site with sub directories, and default 301
Endless Redirect Loop by htaccess rules multi language
Please someone help me..
Thanks!

Rewrite Magento url to Wordpress page

I have a Magento site installed at the root of my domain and a Wordpress installed in a subdirectory. Currently I access my sites like this:
Magento: "domain.com"
Wordpress: "domain.com/blog"
I would like to be able to use Wordpress Pages seamlessly, without the "/blog" subdirectory showing in the url, such as:
Wordpress Page-X: "domain.com/page-x"
Note that I do want to keep the "/blog" subdirectory showing normally for blog posts etc... I just don't want it for Wordpress Pages.
Could anybody help on how to set that up? I was think tweaking the .htaccess would've work, but I can't find out how. Other solutions are welcome too. Thank you.
Magento provides you with an option to create custom URL rewrites in the backend (admin) you can find it here. This way you should be able to create rewrites. Also if you want to automate the creation of rewrites you can refer to the core_rewrites table in magento's database. Also this is a good read if you want to do logic based rewrites on the fly.

Resources