Jump to content

help with nginx rewrite


Recommended Posts

Posted

I tried this

location = /adriano-faria {
     return 301 https://invisionpower.com/profile/114025-adriano-faria/content/?type=downloads_file/
}

it fails. Nginx won't boot until I remove this location block from the config file. ugh.. I can't get my finger on this.

Posted

You simply forgot the semicolon on the second line ^_^

location = /adriano-faria {
     return 301 https://invisionpower.com/profile/114025-adriano-faria/content/?type=downloads_file/;
}

In the future, you should test your nginx configuration before reloading or restarting nginx. I believe the test flag is -t:

$ nginx -t

 

Posted

HI

However, I still can't make it work for the life of me

Now my Nginx isn't crashing and -t passes but it doesn't work!!! :(

Here is my whole nested set of blocks

http {


server {
listen 80 default_server;
server_name mysite.org www.mysite.org;
location = /kyrakane {
return 301 https://www.mystie.org/forum/index.php?/profile/49911-kyrakane/&tab=node_downloads_Files/;
 }
}

#more code for http block here omitted for this post
}

 

Shouldn't I be able to type www.mysite.org/kyrakane and get the link listed above?

Thank you

Posted

Do you want it to keep that path or just redirect?

If its just redirect cant you use:

rewrite ^/kyrakane/(.*)		/forum/index.php?/profile/49911-kyrakane/&tab=node_downloads_Files/$1			permanent;
rewrite ^/kyrakane		/forum/index.php?/profile/49911-kyrakane/&tab=node_downloads_Files/			permanent;

Use 1 of those, the first line is just to show how you can pass a path as a variable but I think the second is what you want.

Just use that in your block at the top-ish area. No location needed.

Posted
4 hours ago, ZeroHour said:

Do you want it to keep that path or just redirect?

If its just redirect cant you use:


rewrite ^/kyrakane/(.*)		/forum/index.php?/profile/49911-kyrakane/&tab=node_downloads_Files/$1			permanent;
rewrite ^/kyrakane		/forum/index.php?/profile/49911-kyrakane/&tab=node_downloads_Files/			permanent;

Use 1 of those, the first line is just to show how you can pass a path as a variable but I think the second is what you want.

Just use that in your block at the top-ish area. No location needed.

I removed location to the above server block and added the second line in your example

www.mysite.com/kyrakane    leads to 404 error page.

Still not working I fear :(

Posted

Not sure why, I use those redirects in the server block under the first few lines of the server block code but before any location blocks in there.

Posted
Just now, Steph40 said:

Do you have:


    location /
    {
        try_files $uri $uri/ /index.php?$args;

    }

inside your server block?

I don't have it anywhere. :(

Posted
11 hours ago, superj707 said:

I don't have it anywhere. :(

Then you need it in your nginx server block for you website or in the default server block.

It is that line that makes the rewrite possible on nginx.

the default.conf server block should look like this:

server {
	root /usr/share/nginx/www;
	index index.php index.html index.htm;

	server_name localhost;

	location /
    {
        try_files $uri $uri/ /index.php?$args;
    }

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		deny all;
	}
}

 

@superj707

If you had this line before:

    location / {
		try_files $uri $uri/ /index.html;
	}

Replace it with:

	location / {
		try_files $uri $uri/ /index.html;
	}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...