Question

.htaccess to nginx rewrite rules i need help for that

  • Posted December 11, 2019
  • Nginx

Can you help me with that rules? I try to implememnt but i take a lot of mistakes and too many redirects, so i want little help with that.

Options +FollowSymLinks -MultiViews
		RewriteEngine On
		RewriteBase /
		
		ErrorDocument 404 https://follow.bgsources/not-found.php          
		RewriteCond %{REQUEST_METHOD} !POST
		RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
		RewriteRule ^ /%1 [R=302,NE,L]
			  
		RewriteCond %{REQUEST_METHOD} !POST
		RewriteCond %{THE_REQUEST} /index\.php [NC]
		RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
			  
		RewriteCond %{REQUEST_FILENAME} -d [OR]
		RewriteCond %{REQUEST_FILENAME} -f
		RewriteRule ^ - [L]
			   
		RewriteRule ^hashtag/([^/]+)/?$ hashtags.php?tag=$1 [L,QSA]
		RewriteRule ^settings/([\w-]+)/?$ settings.php?set=$1 [L,QSA]
		RewriteRule ^credit/([\w-]+)/?$ buyCredit.php?cr=$1 [L,QSA]
		RewriteRule ^status/([^/]+)/?$ status.php?msgID=$1 [L,QSA]
        RewriteRule ^chat/([\w-]+)/?$ chat.php?with=$1 [L,QSA]
		RewriteRule ^account/([\w-]+)/?$ sources/index.php?get=$1 [L,QSA]
		RewriteRule ^dashboard/([\w-]+)/?$ admin/index.php?set=$1 [L,QSA]
		RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,QSA,NC]  
		RewriteRule ^profile/(followers|friends|saved|stories)/([^/]+)/?$ $1.php?username=$2 [L,QSA,NC]
		RewriteRule ^mymarket/([^/]+)/?$ market.php?marketid=$1 [L,QSA,NC]
        RewriteRule ^mymarket/(sold|about)/([^/]+)/?$ market.php?marketid=$2 [L,QSA,NC]
		RewriteRule ^event/([^/]+)/?$ event.php?eventID=$1 [L,QSA,NC] 
        RewriteRule ^events/([\w-]+)/?$ events.php?p=$1 [L,QSA,NC]	  
		RewriteRule ^product/([^/]+)/?$ product.php?productid=$1 [L,QSA]  

        RewriteRule ^marketplace/(category)/([^/]+)/?$ marketplace.php?category=$2 [L,QSA,NC]
        RewriteRule ^marketplace/(search)/([^/]+)/?$ marketplace.php?sproduct=$2 [L,QSA,NC]

		
		RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^([^\.]+)$ $1.php [NC,L]
		
		<IfModule mod_headers.c>
		Header set Access-Control-Allow-Origin '*'
		</IfModule>
		
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.

Hello,

I would suggest checking out the following sites to help you convert the file to something nginx understands:

http://winginx.com/en/htaccess

https://www.nginx.com/blog/converting-apache-to-nginx-rewrite-rules/

Also you could take a look at the Nginx Config Community tool here which might help you to generate your Nginx config file that you need:

https://www.digitalocean.com/community/tools/nginx

Hope that this helps! Regards, Bobby