Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

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

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

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>