emmay
By:
emmay

.htaccess re-writing not working in nginx .getting 404 error

April 15, 2016 619 views
Nginx LEMP

This is the first time i am installing and configuring droplet with ngnix . this application was running in Apache and migrated to nginx . Unfortunately, .htaccess not working .

for example i have given htaccess for aboutus page http://82.196.8.251/about-us/
--RewriteRule ^about-us/ about_us.php [L,QSA] ,but its not working . could you please help me to fix this issue .

I can directly access like :http://82.196.8.251/about_us.php .. But entire this project has been set in .htaccess list..

Thanks in advance !!

2 Answers

Nginx does not support apache .htaccess files. You can however, use this converter to convert your .htaccess into lines to add the the nginx configuration file for your site (found in /etc/nginx/sites-enabled/).

I have tried adding that .. when I click on link the, source code getting downloaded . Please help or advice ...

.htaccess file content example

RewriteRule ^about-us/ about_us.php [L,QSA]

/etc/nginx/sites-enabled/default

location @about-us{
rewrite ^(.*) /about_us.php?$1 last;
}
-----------------------------------------------------------------Entire .htaccessfile content below--------------------

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{SCRIPTFILENAME} !-d
RewriteCond %{SCRIPT
FILENAME} !-f

SetEnv HTTPMYSITEROOT "http://82.196.8.251/"
SetEnv HTTP
MYSITEADMIN "http://82.196.8.251/admin/"

RewriteRule ^about-us/ about_us.php [L,QSA]

SetEnv HTTPMYSITE_ROOT "http://localhost/emmay/" SetEnv HTTPMYSITE_ADMIN "http://localhost/emmay/admin/" SetEnv HTTPMYSITE_ROOT "http://localhost/emmay12/" SetEnv HTTPMYSITE_ADMIN "http://localhost/emmay12/admin/" SetEnv HTTPMYSITEROOT HTTPHOST RewriteRule /about-us/ http://localhost/emmay12/about_us.php [L,QSA] RewriteRule ^(.*)/about-us/ localhost/$1/about_us.php [L,QSA] #[L,R=301] RewriteCond %{HTTP_HOST} !^localhost/emmay12$ [NC]

RewriteRule ^about-us/ about_us.php [L,QSA]
RewriteRule ^promotions/ promotions.php [L,QSA]
RewriteRule ^act-us/ contactus.php [L,QSA]
RewriteRule ^how-to-shop/ howtoshop.php [L,QSA]
RewriteRule ^faq/ faq.php [L,QSA]
RewriteRule ^Jewellery-Care/ jewelcare.php [L,QSA]
RewriteRule ^disclaimer/ disclaimer.php [L,QSA]
RewriteRule ^privacy-policy/ policy.php [L,QSA]
RewriteRule ^terms-and-conditions/ info.php [L,QSA]
RewriteRule ^sitemap/ sitemap.php [L,QSA]
RewriteRule ^home/ index.php [L,QSA]
RewriteRule ^gift/ gift.php [L,QSA]

RewriteRule ^custom-orders/ customorder.php [L,QSA]

RewriteRule ^referralhistory/ referralhistory.php [L,QSA]
RewriteRule ^customorders/ customorders.php [L,QSA]
RewriteRule ^addreferral/ addreferral.php [L,QSA]
RewriteRule ^redemptionhistory/ redemptionhistory.php [L,QSA]
RewriteRule ^orderstatuspending/ orderstatuspending.php [L,QSA]
RewriteRule ^editprofile/ editprofile.php [L,QSA]
RewriteRule ^earnhostory/ earnhostory.php [L,QSA]
RewriteRule ^orderstatuscancel/ orderstatuscancel.php [L,QSA]
RewriteRule ^goldschemestatus/ goldschemestatus.php [L,QSA]
RewriteRule ^changepassword/ changepassword.php [L,QSA]
RewriteRule ^pointshistory/ pointshistory.php [L,QSA]
RewriteRule ^logout/ logout.php [L,QSA]

RewriteRule ^shopping-cart-blank/$ Copyshoppingcart-blank.php?cart=cart [L,QSA]
RewriteRule ^logout/ logout.php [L,QSA]
RewriteRule ^loginregister/?(.*)$ loginregister.php?$1 [L,QSA]
RewriteRule ^loginregister/ loginregister.php [L,QSA]
RewriteRule ^mywishlist/?(.*)$ mywishlist.php?cart=cart&$1 [L,QSA]

RewriteRule ^makebalpayment/?(.*)$ makebalpayment.php?$1 [L,QSA]
RewriteRule ^goldtreepayment/ goldtreepayment.php?name=tree [L,QSA]
RewriteRule ^goldseedpayment/ goldseedpayment.php?name=seed [L,QSA]
RewriteRule ^forgot-password/ forgotpassword.php [L,QSA]
RewriteRule ^customsearch/ customsearch.php [L,QSA]

RewriteRule ^goldtreeconfirm/ goldtreeconfirm.php?name=tree [L,QSA]
RewriteRule ^goldseedconfirm/ goldseedconfirm.php?name=seed [L,QSA]
RewriteRule ^goldtreefaq/ goldtreefaq.php?name=tree [L,QSA]
RewriteRule ^goldseedfaq/ goldseedfaq.php?name=seed [L,QSA]
RewriteRule ^new-user/?(.*)$ newuser.php?$1 [L,QSA]
RewriteRule ^newuser/ newuser.php [L,QSA]

RewriteRule ^mywishlist/ mywishlist.php?cart=cart [L,QSA]
RewriteRule ^thanks-newuser/ thanksnewuser.php [L,QSA]
RewriteRule ^watches
size/ watchessize.php [L,QSA]
RewriteRule ^orderstatus/ orderstatus.php [L,QSA]
RewriteRule ^ring-size/ ring
size.php [L,QSA]
RewriteRule ^email-friend/ emailfriend.php [L,QSA]
RewriteRule ^category/ category.php [L,QSA]
RewriteRule ^bill
ship/ billship.php [L,QSA]
RewriteRule ^list
testimonial/ listtestimonial.php [L,QSA]
RewriteRule ^stonesetting/ stonesetting.php [L,QSA]
RewriteRule ^birthstones/ birthstones.php [L,QSA]
RewriteRule ^pearl/ pearl.php [L,QSA]
RewriteRule ^order
details/?(.)$ order_details.php?$1 [L,QSA]
RewriteRule ^shoppingcart/giftvalidation/?(.
)$ giftvalidation.php/?$1 [L,QSA]
RewriteRule ^shoppingcart/giftvalidation/?(.)$ giftvalidation.php?$1 [L,QSA]
RewriteRule ^shoppingcart/(.
)/(^.)$ shoppingcart.php?cart=cart&pid=$1 [L,QSA]
RewriteRule ^shoppingcart/?(.
)$ shoppingcart.php?cart=cart&$1 [L,QSA]
RewriteRule ^shoppingcart/ shoppingcart.php?cart=cart [L,QSA]

RewriteRule ^goldcoindetails/?(.*)$ goldcoindetails.php?$1 [L,QSA]

RewriteRule ^solitaire-gemstones/?(.*)$ customorder_silver.php?$1 [L,QSA]

RewriteRule ^customordersilver/ customordersilver.php [L,QSA]

RewriteRule ^pointstoredeemgoldetree/ pointstoredeemgoldetree.php [L,QSA]
RewriteRule ^customorderringban/?(.*)$ customorderringban.php?$1 [L,QSA]
RewriteRule ^customorderringban/ customorderringban.php [L,QSA]
RewriteRule ^customorderdiamond/ customorderdiamond.php [L,QSA]

RewriteRule ^goldseedthank/ goldseedthank.php?name=seed [L,QSA]
RewriteRule ^goldtreethank/ goldtreethank.php?name=tree [L,QSA]

RewriteRule ^checkloginstatus/ checkloginstatus.php [L,QSA]
RewriteRule ^join-goldtree/ joingoldtree.php?name=tree [L,QSA]
RewriteRule ^join-goldseed/ join
goldseed.php?name=seed [L,QSA]
RewriteRule ^custorderdetails/?(.*)$ custorderdetails.php?$1 [L,QSA]
RewriteRule ^custorderdetails/ custorderdetails.php [L,QSA]

RewriteRule ^payhistorygs/?(.)$ payhistorygs.php??name=seed&$1 [L,QSA]
RewriteRule ^payhistorygt/?(.
)$ payhistorygt.php??name=tree&$1 [L,QSA]
RewriteRule ^goldtreebillship/?(.)$ goldtreebillship.php?$1 [L,QSA]
RewriteRule ^goldtreebillship/ goldtreebillship.php?name=tree [L,QSA]
RewriteRule ^goldseedbillship/?(.
)$ goldseedbillship.php?name=seed&$1 [L,QSA]
RewriteRule ^goldseedbillship/ goldseedbillship.php?name=seed [L,QSA]
RewriteRule ^sapphire/ sapphire.php [L,QSA]
RewriteRule ^emerald/ emerald.php [L,QSA]
RewriteRule ^ruby/ ruby.php [L,QSA]
RewriteRule ^diamond/ diamond.php [L,QSA]
RewriteRule ^diamond2/ diamond2.php [L,QSA]
RewriteRule ^platinum/ platinum.php [L,QSA]
RewriteRule ^gold/ gold.php [L,QSA]
RewriteRule ^silver/ silver.php [L,QSA]
RewriteRule ^gemmology/ gemmology.php [L,QSA]

RewriteRule ^silverfiligree/ silverfiligree.php [L,QSA]
RewriteRule ^bidri/ bidri.php [L,QSA]
RewriteRule ^thewa/ thewa.php [L,QSA]
RewriteRule ^meenakari/ meenakari.php [L,QSA]
RewriteRule ^kundan/ kundan.php [L,QSA]
RewriteRule ^jadau/ jadau.php [L,QSA]
RewriteRule ^victorian/ victorian.php [L,QSA]
RewriteRule ^pointstoredeem/ pointstoredeem.php [L,QSA]
RewriteRule ^popuptestimonial/(.)/(.) popuptestimonial.php?id=$1 [L,QSA]
RewriteRule ^solitaire-diamond-search/(.)/ diamonds.php?sp=$1&catid=58 [L,QSA]
RewriteRule ^solitaire-diamond-search/(.
) diamonds.php?sp=$1&catid=58 [L,QSA]
RewriteRule ^diamonds/ diamonds.php?catid=58 [L,QSA]
RewriteRule ^diamondpair-search/(.)/ diamondspair.php?sp=$1&catid=58 [L,QSA]
RewriteRule ^diamondpair-search/(.
) diamondspair.php?sp=$1&catid=58 [L,QSA]

RewriteRule ^checkoutship/ checkoutship.php [L,QSA]
RewriteRule ^payment/ payment.php [L,QSA]
RewriteRule ^checkout/ checkout.php [L,QSA]

RewriteRule ^checkoutship/ checkoutship.php [L,QSA]

RewriteRule ^ready-to-ship-jewellery/(.)/product-details/?(.)$ productdetails.php?cart=ready&prod_name=$1&$2 [L,QSA]

RewriteRule ^ready-to-ship-jewellery/(.)/?(.)=(.)$ products.php?cart=ready&prod_name=$1&$2=$3 [L,QSA]
RewriteRule ^ready-to-ship-jewellery/(.
)/ products.php?cart=ready&prod_name=$1 [L,QSA]

RewriteRule ^ready-to-ship-jewellery/(.)/?(.) products.php?prod_name=$1&$2 [L,QSA]

RewriteRule ^custom-orders/product-details/(.)/ productdetails.php?catid=2&prod=$1 [L,QSA]
RewriteRule ^custom-orders/ customorder.php?catid=2 [L,QSA]
RewriteRule ^gold-coins/ goldcoins.php?catid=65 [L,QSA]
RewriteRule ^fast-moving/product-details/(.
)/ productdetails.php?prod=$1 [L,QSA]
RewriteRule ^gold-tree/ goldtree.php?name=tree [L,QSA]
RewriteRule ^gold-seed/ goldseed.php?name=seed [L,QSA]
RewriteRule ^gift-certificates/ gift.php?catid=1 [L,QSA]

RewriteRule ^featured-items/product-details/(.)/ productdetails.php?prod=$1 [L,QSA]
RewriteRule ^featured-items/goldcoin-details/(.
)/ goldcoins.php?catid=$1 [L,QSA]

RewriteRule ^(.)/product-details/?(.)$ productdetails.php?$2 [L,QSA]
RewriteRule ^jewellery-search/(.*)$ products.php?search=1&$1 [QSA,L]

RewriteRule ^listproduct/?(.*)$ listproduct.php?$1 [L,QSA]

RewriteRule ^diamond-details/(.)/ diamond_details.php?pid=$1 [L,QSA]
RewriteRule ^product-details/(.
)/ productdetails.php?prod=$1 [L,QSA]

to show diamond details BUILT YOUR OWN JEWELLARY

RewriteRule ^make-your-own-pendent/choose-your-setting/(.)/ customproitem.php?pid=$1&custpid=61&catid=61 [L,QSA]
RewriteRule ^make-your-own-ring/choose-your-setting/(.
)/ customproitem.php?pid=$1&custpid=63&catid=63 [L,QSA]
RewriteRule ^make-your-own-earring/choose-your-setting/(.*)/ customproitem.php?pid=$1&custpid=60&catid=63 [L,QSA]

to view diamond details of make your own item section diamond details RewriteRule ^diamond-details/(.*)/ diamond_details.php?pid=$1 [L,QSA]

RewriteRule ^make-your-own-earring/diamond-details/(.)/?dd=(.)$ diamond_details.php?catid=60&pid=$1&dd=$2 [L,QSA]

RewriteRule ^make-your-own-jewellery/select-your-diamonds/ diamonds.php?catid=58 [L,QSA]
RewriteRule ^make-your-own-pendent/diamond-details/(.)/ diamond_details.php?catid=61&pid=$1 [L,QSA]
RewriteRule ^make-your-own-ring/diamond-details/(.
)/ diamonddetails.php?catid=63&pid=$1 [L,QSA]
RewriteRule ^solitaire-diamonds/diamond-details/(.*)/ diamond
details.php?catid=60&pid=$1 [L,QSA]
RewriteRule ^make-your-own-jewellery/diamond-details/(.*)/ diamond_details.php?catid=58&pid=$1 [L,QSA]

static link of make your own item

RewriteRule ^make-your-own-pendent/select-your-diamonds/ customprodia.php?catid=61 [L,QSA]
RewriteRule ^make-your-own-ring/select-your-diamonds/ customprodia.php?catid=63 [L,QSA]
RewriteRule ^solitaire-diamonds/choose-pairs-for-earring/ customprodia.php?catid=60 [L,QSA]

RewriteRule ^solitaire-diamonds/ loosedia.php [L,QSA]
RewriteRule ^solitaire-diamonds-details/(.*)/ loose
diamond_details.php?pid=$1 [L,QSA]

RewriteRule ^make-your-own-pendent/choose-your-setting/ customproitem.php?catid=61 [L,QSA]
RewriteRule ^make-your-own-ring/choose-your-setting/ customproitem.php?catid=63 [L,QSA]
RewriteRule ^make-your-own-earring/choose-your-setting/ customproitem.php?catid=60 [L,QSA]

RewriteRule ^make-your-own-pendent/complete-your-pendent/(.)/ customprocomplete.php?catid=61&prod=$1 [L,QSA]
RewriteRule ^make-your-own-ring/complete-your-ring/(.
)/ customprocomplete.php?catid=63&prod=$1 [L,QSA]
RewriteRule ^make-your-own-earring/complete-your-earring/(.*)/ customprocomplete.php?catid=60&prod=$1 [L,QSA]

RewriteRule ^make-your-own-pendent/complete-your-pendent/ customprocomplete.php?catid=61 [L,QSA]
RewriteRule ^make-your-own-ring/complete-your-ring/ customprocomplete.php?catid=63 [L,QSA]
RewriteRule ^make-your-own-earring/complete-your-earring/ customprocomplete.php?catid=60 [L,QSA]

error reporting page

RewriteRule ^error404/ 404.php [L,QSA]
RewriteRule ^error404 404.php [L,QSA]

Have another answer? Share your knowledge.