C4f1151075b447779af31e99d6cf70e2c6eb47ac
By:
newbie

Converting htaccess rules to Nginx

November 17, 2016 120 views
Nginx WordPress Ubuntu 16.04

Hi,
i need to convert bellow htaccess rule for my nginx server. i have tried to convert and bellow is my result. unfortunately its not working. can somebody tell me where i have done wrong?

Original htaccess rule
RewriteRule ^other/(.*) /wp-includes/$1?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^file/(.*) /wp-content/uploads/$1?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^ext/(.*) /wp-content/plugins/$1?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^skin/([_0-9a-zA-Z-]+)/main.css /index.php?style_wrapper=true&template_wrapper=$1&sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^skin/([_0-9a-zA-Z-]+)/style\.css /nothing_404_404?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^skin/(.*) /wp-content/themes/$1?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?ajax /wp-admin/admin-ajax.php?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^inc/(.*) /wp-content/$1?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^(readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$) /nothing_404_404?sEyM_hide_my_wp=1234 [QSA,L]
RewriteRule ^(((wp-content|wp-includes)/([A-Za-z0-9\-\_\/]*))|(wp-admin/(!network\/?)([A-Za-z0-9\-\_\/]+)))(\.txt|/)$ /nothing_404_404?sEyM_hide_my_wp=1234 [QSA,L]

Converted Nginx rule

location /other { 
    rewrite ^/other/(.*) /wp-includes/$1?sEyM_hide_my_wp=1234 break; }

    location /file { 
    rewrite ^/file/(.*) /wp-content/uploads/$1?sEyM_hide_my_wp=1234 break; }

    location /ext { 
    rewrite ^/ext/(.*) /wp-content/plugins/$1?sEyM_hide_my_wp=1234 break; }

    location /skin { 
    rewrite ^/skin/([_0-9a-zA-Z-]+)/main.css /index.php?style_wrapper=true&template_wrapper=$1&sEyM_hide_my_wp=1234 break; 
    rewrite ^/skin/([_0-9a-zA-Z-]+)/style\.css /nothing_404_404?sEyM_hide_my_wp=1234 break; 
    rewrite ^/skin/(.*) /wp-content/themes/$1?sEyM_hide_my_wp=1234 break; } 

    location /inc { 
    rewrite ^/inc/(.*) /wp-content/$1?sEyM_hide_my_wp=1234 break; }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
        # try_files $uri $uri/ /index.html;
        # try_files $uri $uri/ =404;
        rewrite ^/([_0-9a-zA-Z-]+/)?ajax /wp-admin/admin-ajax.php?sEyM_hide_my_wp=1234 break;
        rewrite ^/(readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$) /nothing_404_404?sEyM_hide_my_wp=1234 break;
        rewrite ^/(((wp-content|wp-includes)/([A-Za-z0-9\-\_\/]*))|(wp-admin/(!network\/?)([A-Za-z0-9\-\_\/]+)))(\.txt|/)$ /nothing_404_404?sEyM_hide_my_wp=1234 break;
    }

thanks in advance.

2 Answers

If you're trying to add rules for the Hide My WP plugin, they have Nginx settings in their documentation - http://support.wpwave.com/docs/hide-my-wp/#nginx_config

  • hello @jesin
    thanks for the reply.

    i have tried all settings, even the one from their doc but unfortunately didnt worked for my setup. i was trying to use that plugin with Nginx multi-site. after having the right setting the plugin actually works at front, but there are tons of errors remain which is why they have asked to request for a refund.

    thanks for your response anyway. :)

    by the way, could you help me a bit with following Nginx Keepalive settings?

    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    

    i have read the nginx documentation but some details explanation would be very much appreciated. like its not clear to me that i should use them only when im using upstream or even when using unix socket.

    also if im using php, above will go into location php, right?

     location ~ \.php$ {
                 . . .
                proxy_http_version 1.1;
                proxy_set_header Connection "";
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                 . . .
               }
    

    thanks in advance.

The correct result is as below -

location /other {
rewrite ^/other/(.*) /wp-includes/$1?sEyM_hide_my_wp=1234 break;
}
location /file {
rewrite ^/file/(.*) /wp-content/uploads/$1?sEyM_hide_my_wp=1234 break;
}
location /ext {
rewrite ^/ext/(.*) /wp-content/plugins/$1?sEyM_hide_my_wp=1234 break;
}
location /skin {
rewrite ^/skin/([_0-9a-zA-Z-]+)/main.css /index.php?style_wrapper=true&template_wrapper=$1&sEyM_hide_my_wp=1234 break;
rewrite ^/skin/([_0-9a-zA-Z-]+)/style\.css /nothing_404_404?sEyM_hide_my_wp=1234 break;
rewrite ^/skin/(.*) /wp-content/themes/$1?sEyM_hide_my_wp=1234 break;
}
location / {
rewrite ^/([_0-9a-zA-Z-]+/)?ajax /wp-admin/admin-ajax.php?sEyM_hide_my_wp=1234 break;
rewrite ^/(readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$) /nothing_404_404?sEyM_hide_my_wp=1234 break;
rewrite ^/(((wp-content|wp-includes)/([A-Za-z0-9\-\_\/]*))|(wp-admin/(!network\/?)([A-Za-z0-9\-\_\/]+)))(\.txt|/)$ /nothing_404_404?sEyM_hide_my_wp=1234 break;
}
location /inc {
rewrite ^/inc/(.*) /wp-content/$1?sEyM_hide_my_wp=1234 break;
}
  • hi,
    i tried your code but didnt worked. i also tried replacing break with last but still no luck

Have another answer? Share your knowledge.