Question

.htaccess to nginx rewrite rules i need help for that

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>
		

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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