Opened 11 years ago
Closed 11 years ago
#25098 closed enhancement (fixed)
Support URL rewrites on Nginx
Reported by: | johnbillion | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Rewrite Rules | Keywords: | has-patch |
Focuses: | Cc: |
Description
Splitting this out from #18852.
In order to get URL rewrites without the index.php
prefix on Nginx you need to use the got_rewrite
filter. Less than ideal. Let's correctly detect Nginx and allow it to use nice URL rewrites.
Patch coming up.
Attachments (1)
Change History (13)
#4
follow-ups:
↓ 5
↓ 6
↓ 7
@
11 years ago
The one thing that this patch is lacking, is the fact that by default nginx isn't configured for url rewriting, but we do configure Apache/IIS as best we can for rewrites.
I wish we could detect this via a local HTTP callback + transient cache or something..
#5
in reply to:
↑ 4
@
11 years ago
Replying to dd32:
The one thing that this patch is lacking, is the fact that by default nginx isn't configured for url rewriting, but we do configure Apache/IIS as best we can for rewrites.
I wish we could detect this via a local HTTP callback + transient cache or something..
The HttpRewriteModule is one of the standard modules and the only way for it not to be installed is if Nginx is compiled with the --without-http_rewrite_module flag. That still doesn't mean that the user has rewrite rules properly configured.
One thing we could do is write the configuration in the root web directory and update the codex examples to include this file in their server configurations. This is how W3 Total Cache writes to the nginx config.
One option would be if Nginx is detected create a test rewrite rule then send a HTTP request to see the response code. If we get back a 404 then got_rewrite returns false.
The other problem with writing to the config is the server has to be restarted for the changes to take. Kind of interesting how Drupal does it, http://drupalcontrib.org/api/drupal/contributions!provision!http!Provision!Service!http!nginx.php/6
#6
in reply to:
↑ 4
@
11 years ago
Replying to dd32:
The one thing that this patch is lacking, is the fact that by default nginx isn't configured for url rewriting, but we do configure Apache/IIS as best we can for rewrites.
This is being addressed in #18852. The user will be shown the recommended Nginx configuration on the Permalinks screen, in the same way the recommended .htaccess rules are shown if it's not writable, or the recommended IIS web.config if it's not writable.
Effectively, we're treating the Nginx config as not writable. This mirrors the behaviour of WordPress when the server is running Apache and the .htaccess file is not writable.
Replying to c3mdigital:
One thing we could do is write the configuration in the root web directory and update the codex examples to include this file in their server configurations. This is how W3 Total Cache writes to the nginx config.
Note that W3TC doesn't write to the actual Nginx config file. It writes to a dummy file called nginx.conf in the server's document root, and it's up to the user to copy or merge those rules into their actual Nginx config file.
Writing the config rules to a dummy nginx.conf file in the document root serves no purpose; we may as well just show the rules on the Permalinks screen.
#7
in reply to:
↑ 4
;
follow-up:
↓ 8
@
11 years ago
Replying to dd32:
I wish we could detect this via a local HTTP callback + transient cache or something..
That'd be a great feature for all the setups, not just nginx. Something like /wp-internal-test
, then just check that we don't get an error.
25098.diff adds support for detection of Nginx and adds a
got_url_rewrite()
function as a wrapper for detecting any kind of rewrite support.What this patch ultimately does is allow WordPress to generate URL rewrites which don't get
index.php
prepended.