Opened 4 years ago
Last modified 3 years ago
#2199 new enhancement
Online documentation: converting rewrite rules typo
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | documentation | Version: | 1.18.x |
Keywords: | RewriteRule | Cc: | |
uname -a: | Linux ... 5.8.0-53-generic #60-Ubuntu SMP Thu May 6 07:46:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux | ||
nginx -V: |
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-HdenXw/nginx-1.18.0=. -fstack-protector-strong -Wfor
mat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z, now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-pa th=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules -- http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/ nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug -- with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module - -with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gun zip_module --with-http_gzip_static_module --with-http_sub_module |
Description
In https://nginx.org/en/docs/http/converting_rewrite_rules.html
is a typo in the converted rewrite rules:
Another example. Instead of the “upside-down” logic “all that is not example.com and is not www.example.com”:
RewriteCond %{HTTP_HOST} !example.com RewriteCond %{HTTP_HOST} !www.example.com RewriteRule (.*) http://www.example.com$1
one should simply define example.com, www.example.com, and “everything else”:
server { listen 80; server_name example.com www.example.com; ... } server { listen 80 default_server; server_name _; return 301 http://example.com$request_uri; }
The last above bit ...
return 301 http://example.com$request_uri;
... should be ...
return 301 http://www.example.com$request_uri;
... as that is what is requested in the apache rewrite rule ...
RewriteRule (.*) http://www.example.com$1
Same applies to the old version part...
On versions prior to 0.9.1, redirects can be made with:
rewrite ^ http://example.com$request_uri?;
... should be ...
rewrite ^ http://www.example.com$request_uri?;
OR change the Apache rewrite rule into:
RewriteRule (.*) http://example.com$1
Note:
See TracTickets
for help on using tickets.
Ticket retargeted after milestone closed