I have a wordpress website and a I need rewrite:
myurl.com/name-of-my-post/?lang=es
To
myurl.com/es/name-of-my-post/
I allready try everthing that i can found but not is working
P.S I don't need send the lang parameter to index.php becausa there is a plugin that reply to
myurl.com/es/name-of-my-post/ but not rewrite when a visit come from myurl.com/name-of-my-post/?lang=es
Thanks for the help
A simple fix (which may not work because it is too simple) is to permanently redirect any URI with a lang parameter:
if ($arg_lang) {
return 301 /$arg_lang$uri;
}
See this caution on the use of the if directive.
Related
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!
I'm trying to make redirect on nginx but unfortunately it doesn't work.
What I'd like to achieve, it is to redirect amp files on mobile.
What I'd like to do :
from
https://www.example.com/uri-759.html
to
https://www.example.com/uri-759-amp.html
What I did as redirect
if ($mobile_redirect = perform) {
redirect ^(.*)(\.html)$ $1-amp$2 permanent;
}
what I obtain
https://www.example.com/uri-759-amp-amp-amp-amp-amp-amp-amp-amp.html
Does someone have a solution to perform this redirection ?
You can use a negative lookbehind assertion to avoid matching the rewritten URI.
For example:
rewrite ^(.*)(?<!-amp)(\.html)$ $1-amp$2 permanent;
See this document for more.
I am trying to solve an issue with link rot that is a result from a permalink change a year ago on a high traffic site. I know you can redirect certain permalink structures in apache but how is this done in regex?
I need to move all link request that are in this format:
http://www.*****.com/permalinks/year/month/day/title
to this current (as of 2015) format:
http: //www.*****.com/year/month/day/title
Basically I just need to remove the name permalinks from the url request to fetch it from the database.
I tried forcing a search on anything with a 404 but it has not been reliable, along with it being very slow since the database is large.
I tried this in regex but it does not work:
/permalinks/(d*)/(d*)/(d*)/(.*) => /(d*)/(d*)/(d*)$4
You need simple regex rewrite for remove permalinks/ and keep rest of url:
server {
listen 80;
server_name example.com;
rewrite ^/permalinks/(.*) http://example.com/$1 permanent;
}
Thanks for the response. I will look into that code. It appears to be for nginx.conf? I do not have access to that at the moment so I can't try it.
I went with this regular expression through the urban giraffe redirection plugin and it works:
/permalinks/(.*) ==> /$1
My nginx site has a few bad links pointing to it like this:
/some-page%23some-part
/some-page">
This is causing 404's and Google Webmaster Tools is complaining too.
The URL /some-page#some-part does get processed properly and works.
How can I get nginx to redirect the %23 in a URL to #? What about the "> junk?
The links out there cannot be changed, so I'm looking to 301 redirect them myself.
Thanks!
Edit: thanks to Deadooshka for the help. My working solution, rewrite ^(.*)\#(.*)$ /$1#$2 redirect;, is discussed within his answer's comment thread.
not tested. I'm not sure which symbols get the pattern.
rewrite ^/([^\#]+)\#([^\#]+)$ /$1#$2 redirect;
rewrite '^/([^\&]+)\"\;\>\;$' /$1 redirect;
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;