1

I've read the nginx documentation and I've read probably more than 10 post about similar issues on here, but I'm still not able to get this working right.

My basic redirects are working, but when I try to make a rewrite with some parameters, the page ends up loading funny. Just the html is loaded and all other css, images, and js files aren't loaded correctly.

I'm working on Wginx and this is the config I'm working with.

location ~ /\. {deny all;}

    location / {

        rewrite ^/index /index.php last;
        rewrite ^/arcade /arcade.php last;
        rewrite ^/info /info.php last;
        rewrite ^/info/(.*)$ /info-entry.php?pki=$1 last;


        if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
            root home/$2/public_html;
            access_log  logs/$2-access.log  main;
        }

    }

    location ~ \.php$ {

        if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
            root home/$2/public_html;
            access_log  logs/$2-access.log  main;
        }

        if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass localhost:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

    }

The first 3 rewrites work fine (but I do think there's a simpler way to just cut the .php off instead of have a rewrite for every file)

I noticed that when I removed the following line I get some slightly different results from my info-results.php page. Not sure what's going on really.

rewrite ^/info /info.php last;
1
  • Ryan's <base> method helped me getting the page with the parameters working correctly. But, then the rewrite above it wasn't working. It seems there was some syntax problem in my regular express and it should have been rewrite ^/info$ /info.php last;. I originally missed the closing "$". Show be enclosed with a ^ and $ to get an exact match. Commented Jan 27, 2014 at 12:12

1 Answer 1

1

Try specifying a base tag in your <head></head>

E.g.

<base href="http://www.website.com/" target="_blank">

See <base> tag

Sign up to request clarification or add additional context in comments.

2 Comments

That didn't work. The weird thing is when I look at the output code after the page loads that <base> tag isn't even their. But when I load the pages by just going to the actual file path it's their.
Ok. So I remove the rewrite ^/info /info.php last; line and then tried it with the base tag and it worked. Do you know how I could write these rewrites so I can get both to work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.