Welcome! Log In Create A New Profile

Advanced

How to use a rewrite AND a redirect at the same time (in location?)

Posted by robiso 
How to use a rewrite AND a redirect at the same time (in location?)
February 07, 2015 08:00AM
Hello everyone.

I'm really having trouble grapsing the problem I'm trying to solve.
First, I have a cms which shows pages as:

http://example.com/?page=home

What I have so far that works to make a clean url like http://example.com/home (in my /etc/nginx/sites-available/example.com.vhost):

location / {
rewrite ^/([^.]+)$ /?page=$1
last;
}

But what doesn't work is, if I have the same CMS on another directory (or multiple CMSes), for example : example.com/anotherlocation/here

And if I try:
location /anotherlocation/here {
rewrite ^/([^.]+)$ /?page=$1
last;
}
Clean URLs simply dont work in /anotherlocation/here

Is there anything I'm doing wrong?
I'm also having trouble combining a default redirect to index.php when an index.php exsists..

This also didn't seem to work (tried to fix to redirect to index.php by deault and rewrite /?page=home to /home
location / {
try_files $uri $uri/ /index.php;
rewrite ^/([^.]+)$ /?page=$1
last;
}
Re: How to use a rewrite AND a redirect at the same time (in location?)
February 07, 2015 09:14AM
For the whole config and a briefer explanation check: http://p.ngx.cc/5d
Re: How to use a rewrite AND a redirect at the same time (in location?)
February 07, 2015 12:24PM
I managed to patch up a solution for every directory/folder on the website to load an index.php first (if it has one).
http://p.ngx.cc/53
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 182
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready