Sample Header Ad - 728x90

Redirect all example.com/paths that don't start with example.com/wiki to example.com/wiki - NginX Proxy

1 vote
1 answer
251 views
I recently moved my site from Wordpress to confluence, and I'm having trouble with page redirects. Ive setup a custom 404 page for my Confluence, but it only works if you type https://www.freesoftwareservers.com/asdasdas But if you go to an old link, like https://www.freesoftwareservers.com/index.php/2015/09/03/install-dd-wrt-on-linksys-ea6500/ It takes you to my "confluence" page, but the /wiki is a special plugin that I want to be the public facing side. I access the page via a different subdomain then www. My "workaround" would be one of two things, 1) Redirect all https://www.freesoftwareservers.com/index.php/* to https://www.freesoftwareservers.com/wiki 2) Redirect all https://www.freesoftwareservers.com/(Anything BUT /wiki) to https://www.freesoftwareservers.com/wiki I found something close on NginX site, but it was more complicated that what I need and I was having trouble with the expression needed. https://www.nginx.com/blog/creating-nginx-rewrite-rules/ Here’s a sample NGINX rewrite rule that uses the rewrite directive. It matches URLs that begin with the string /download and then include the /media/ or /audio/ directory somewhere later in the path. It replaces those elements with /mp3/ and adds the appropriate file extension, .mp3 or .ra. The $1 and $2 variables capture the path elements that aren’t changing. As an example, /download/cdn-west/media/file1 becomes /download/cdn-west/mp3/file1.mp3. server { ... rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last; return 403; ... } Perhaps I need to split this into 2 parts, a server block that returns 404 and a 404 handler, but I'd like to keep this all in my existing nginx server block. BTW I am already using the following rewrite rule to redirect domain.com/ to domain.com/wiki, but that only works if you type https://www.freesoftwareservers.com without anything at the end. rewrite ^/$ /wiki permanent; Any help is appreciated, there are many broken links to my site floating around the interweb :)
Asked by FreeSoftwareServers (2682 rep)
Oct 10, 2016, 02:52 AM
Last activity: Jul 4, 2018, 07:17 AM