WordPress.org

Ready to get started?Download WordPress

Forums

Question on index.php (3 posts)

  1. rakhesh
    Member
    Posted 7 years ago #

    Hi!

    This is probably a very dumb question. I've done a bit of searching around the forums and Google for an answer to this. Didn't come up with anything.

    I have wordpress up and running on an Nginx web server. Everything works -- permalinks, etc etc. In my Nginx configuration file, I have a snippet such as this which is the equivalent to Apache's mod_rewrite rules:

    -----8<---------
    if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php?q=$1 last;
    }
    -----8<---------

    My question is, how does this work? More specifically, I know that with the rule in place, a URL like http://myblog/path/to/post gets rewritten internally and I am shown the correct post. So shouldn't that mean without such a rewriting rule, if I use a URL like http://myblog/index.php?q=path/to/my/post I should get the correct post?

    But I don't. It doesn't seem to work. Any ideas why? Is the index.php?q=whatever bit not meant to be called directly? I just wanted to confirm that bit first before I look into the Nginx side and figure if that's where I should probe more ...

    Thanks and Regards,
    Rakhesh

  2. honewatson
    Member
    Posted 6 years ago #

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Normally, rewrites don't change the path into a q= variable. WordPress is not looking for the q variable, so your rewrite rule won't work.

    An internal rewrite keeps the same URL but actually calls the index.php file. I don't know where the q= stuff came from.

    Google tells me that this might work:

    if (!-e $request_filename) {
            rewrite ^/.*$ /index.php last;
        }

    Inside the server {...} bit.

Topic Closed

This topic has been closed to new replies.

About this Topic