Question

Converting htaccess rules to Nginx

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 ^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.
Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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

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;
}