I got a problem for vBulletin archive running on Nginx 0.8.54. The Nginx gives me 404 error when I try visiting the following URLs
http://mydomain.com/forums/archive/index.php/t-19.html
http://mydomain.com/forums/archive/index.php/f-19.html
All other things of vBulletin works fine. Can anybody may share its rewrite rule to fix my problem ?Thanks.
Try something like:
location /archive {
rewrite ^/archive/index.php/t-([0-9]+)\.html /archive/index.php?t-$1.html last;
rewrite ^/archive/index.php/f-([0-9]+)\.html /archive/index.php?f-$1.html last;
}
Related
I need help with my nginx configuration.
The goal is to have all requests to my site like site/page1 site/smth/page1 be redirected to just site/ and site/smth/ basically for all requests ending like page[number]
I tried some examples that I found like rewrite ^/page/(.*)$ /$1; still wasn't able to get the redirection. Maybe I misplaced it, not quite sure where I should put the sting. Tried location and server blocks.
The nginx documentation examples for redirecting were a bit too hard to understand for me, so a little explanation would be great.
If you need a 301 HTTP redirection, try this rewrite rule (before the first location block):
rewrite ^(.*/)page\d+$ $1 permanent;
You can try something like this (not tested)
location ~ ^/(.+)/page[0-9]+$ {
rewrite ^/(.+)/page[0-9]+$ /$1 last;
}
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;
I am trying to set up multiple Wordpress sites in sub-folders under our domain (ie not multi-site), but I have difficulty configuring the REST API endpoints. For example, this endpoint works fine:
https://example.com/site1/?rest_route=/wp/v2/posts
But this endpoint gives a 404:
https://example.com/site1/wp-json/wp/v2/posts
I have tried to rewrite the failing url to the working url with these rules in my nginx configuration:
location /site1/wp-json {
rewrite ^/site1/wp-json(.*)$ /site1/?rest_route=$1;
}
location /site1/ {
try_files $uri $uri/ /site1/index.php$is_args$args;
}
I can't see any special handling of wp-json in the WordPress docs or the nginx wiki. What am I missing here? The permalinks for the site is set to Numeric (https://example.com/site1/archives/123) if that might play a role.
Update
Gist of the redacted full config file and the config syntax lints okay:
nginx -c /etc/nginx/nginx.conf -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
I just hit this too, in WP 5.7. Without pretty permalinks, ie with the "Plain" option like ?p=123, my nginx WP installation uses requests like:
/index.php?rest_route=/wp/v2/users/&who=authors...
And these all work fine.
However if I enable pretty permalinks, eg "Post name", /sample-post/, it starts making requests like:
/wp-json/wp/v2/users/?who=authors...
And these all return a 404. For example, editing or publishing posts fails, and browser devtools shows a string of 404s in this format.
But now we know the pattern that works, a solution is clear - we just need to map the not-working format to the working format:
# Resolves WP Gutenberg 404 issue
location /wp-json {
rewrite ^/wp-json(.*)$ /index.php?rest_route=$1 last;
}
I believe that the rewrite directive should be written as shown below:
server {
location /site1/wp-json
{
rewrite ^(/site1/wp-json.*)$ /site1/?rest_route=$1 last;
}
}
I was able to resolve it like this:
location /wordpress/ {
rewrite ^/wordpress/wp-json/(.*?)$ /wordpress/index.php?rest_route=/$1 last;
}
An easy way if your website pages in the subfolder is already working, just add index.php to the url:
https://site1.com/site2/index.php/wp-json/
If your website pages still doesn't work in the subfolder, add this code to nginx/sites-available/website.conf file too:
location /site2 {
rewrite ^(/[^/]+)?(/wp-.*) /site2/$2 break;
rewrite ^/site2/(.*)$ /site2/index.php?q=$1 last;
}
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.
On my site my users click on a profile and the link shows up as www.website.com/profile/username and I would like it to only be www.website.com/username - any suggestions on how I can do this
Note: my webserver is nginx so using rewrite rules is ok, but I would want to know how to write them in the config file
Use the following rewrite rule:
rewrite ^/profile/(.*)$ /$1 permanent;