Jump to content

help with nginx rewrite


Recommended Posts

I want to give my members who contribute to downloads an easy URL to distribute.

I am thinking it can be done with rewrites in the niginx config file but not sure how to make it work.

For example how can I make

https://invisionpower.com/adriano-faria/

lead to

https://invisionpower.com/profile/114025-adriano-faria/content/?type=downloads_file

help appreciated.

Thank you :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

16 minutes ago, superj707 said:

like this app, it's clean and well done.

As far as I can tell though, it only gets me here https://www.mysite.com/forum/index.php?/kyrakane
which is a start but I really want www.mysite.com/kyrakane might not be able to get there.

Do you have:

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

    }

inside your server block?

Link to comment
Share on other sites

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;
	}

 

Link to comment
Share on other sites

Archived

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

  • Recently Browsing   0 members

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