0

I'm trying to setup a friendly URL for a website running on my Nginx server but for some reason, the url's are being redirected instead of being rewritten.

For instance If a user visits mydomain.com/aboutme/ I want mydomain.com/aboutme/ to stay in the address bar, but for the content to be pulled from mydomain.com/aboutme.php

In my Nginx site configuration I have the following (a simple example with some stuff chopped out for simplicities sake):

server {
    listen 1.2.3.4:80;
    server_name www.mydomain.com;

    location / {
        rewrite ^/aboutus/$ http://www.mydomain.com/aboutus.php permanent;
    }

}

For whatever reason, Nginx seems to insist on redirecting the 'friendly' url to the php file, but I want a more traditional "rewrite" (like I've done before in Apache mod_rewrite without issue).

I'm probably doing something wrong, but I'll be damned if I can work out what.

1

1 Answer 1

2

You're getting a 301 redirect because you specifically asked for a 301 redirect.

To fix the problem, use a relative destination URL, and last instead of permanent.

For example:

rewrite ^/aboutus/$ /aboutus.php last;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .