Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have installed wordpress in a subdirectory (blog). In the root directory I have installed Magento. Now the file directory is as following:

app
downloader
includes
media
....
blog/wp-admin

My server is nginx. When I set the URL in the wordpress Permalink Settings to:

http://www.example.com/blog/index.php/sample-post/ 

… all the posts are available. Now I want to remove the index.php from that URL. How should I do that? When I set the custom structure to …

http://www.example.com/blog/sample-post/

… the URLs are not resolved by WordPress and I get a 404.

share|improve this question
    
What does your .htaccess look like? See serverfault.com/questions/206491/… –  Dustin Jan 16 '13 at 6:11
1  
I suggest searching this site for nginx pretty permalinks, this has been asked and answered before. –  Milo Jan 16 '13 at 6:19
add comment

2 Answers

Place this code in your functions.php file

   add_filter( 'got_rewrite', '__return_true', 999 );

Update:

got_mod_rewrite() function checks whether the current server is apache or not using apache_mod_loaded() function. Since we are using nginx it returns false. So wordpress adds index.php in the url.

By using got_rewrite filter we are telling wordpress that we got rewrite in our server.

share|improve this answer
    
i put the code in functions.php. all the post still can't available. –  stack2013110 Jan 17 '13 at 1:10
    
Try resetting your permalink in the permalinks section. First change it to default settings, then switch back –  Giri Jan 17 '13 at 8:34
add comment

The problem likely has to do with the server settings in Nginx for your blog. It's likely that the location rules for /blog/ are wrong, specifically try_files. It should look like this:

location /blog/ {
     try_files $uri $uri/ /index.php$is_args$args;
}

This tells Nginx the order in which it should try to find the requested resource. It will first start by trying to find the exact object in the URL. If that doesn't exist, it'll try to find that object as a directory. If that doesn't exist, it'll pass the request to index.php along with any arguments or query strings, if present. Since index.php in the main handler for WordPress, this will trigger WordPress to find the page or post you've requested based on your rewrite rules.

The beautiful thing about this configuration is that you can now change your permalink structure to anything WordPress supports without having to change your Nginx rules. This is also the recommended method over using explicit rewrite rules in Nginx.

share|improve this answer
    
You'll also want to make sure 'index index.php' is added inside the location rules. –  Christiaan Apr 18 '13 at 18:34
    
Awesome, I didn't have idea this actually existed. Just tried it and it's WAY more useful, since I just only have to remember to write it once (and it works for every wordpress site I have in the vps). –  pablox May 11 '13 at 3:09
    
Yup. It's a much more elegant solution than writing if statements, and more reliable. –  Christiaan May 31 '13 at 14:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.