Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > HOWTO-Related Questions

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 25th March 2013, 23:47
ababneh ababneh is offline
Junior Member
 
Join Date: Mar 2013
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default Please help convert htaccess to nginx

Hey,

I installed ispconfig/nginx on ubuntu 12.10 following your great how-to:

http://www.howtoforge.com/perfect-se...ispconfig-3-p4

I need to apply rewrite rules to nginx from a .haccess file with these contents:

Code:
RewriteEngine On
RewriteRule ^index.html$ index.php
RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1
RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3

RewriteRule ^register.html$ register.php
RewriteRule ^contact_us.html$ contact_us.php
RewriteRule ^edit_profile.html$ edit_profile.php
RewriteRule ^suggest.html$ suggest.php
RewriteRule ^upload.html$ upload.php
RewriteRule ^upload_avatar.html$ upload_avatar.php
RewriteRule ^suggest.html$ suggest.php

RewriteRule ^favorites.html(.*)$ favorites.php$1
RewriteRule ^login.html(.*)$ login.php$1
RewriteRule ^newvideos.html(.*)$ newvideos.php$1
RewriteRule ^topvideos.html(.*)$ topvideos.php$1
RewriteRule ^profile.html(.*)$ profile.php$1
RewriteRule ^favorites.html(.*)$ favorites.php$1
RewriteRule ^playlist/(.*)$ myfavorites.php?u=$1
RewriteRule ^memberlist.html(.*)$ memberlist.php$1

RewriteRule ^articles/read-(.*)_([0-9]+).html$ article_read.php?a=$2
RewriteRule ^articles/index-([0-9]+).html$ article.php?page=$1
RewriteRule ^articles/browse-(.*)-([0-9]+).html$ article.php?c=$1&page=$2
RewriteRule ^articles/tag/([^/]+)/page-([0-9]+)(/)?$ article.php?tag=$1&page=$2
RewriteRule ^articles/tag/([^/]+)(/)?$ article.php?tag=$1&page=1
RewriteRule ^articles/popular-([0-9]+).html$ article.php?show=popular&page=$1
RewriteRule ^articles(\/|.html)?$ article.php
RewriteRule ^article(\/|.html)?$ article.php
RewriteRule ^pages/(.*)\.html$ page.php?name=$1

RewriteRule ^tags/([^/]+)/$ tag.php?t=$1&page=1
RewriteRule ^tags/([^/]+)/page-([0-9]+)(/)?$ tag.php?t=$1&page=$2
RewriteRule ^(.*)/(.*)-video_(.*).html$ musicvideo.php?vid=$3
RewriteRule ^([^/]*)-video_(.*).html$ watch.php?vid=$2
RewriteRule ^fpembed-(.*).swf$ fpembed.php?vid=$1
RewriteRule ^rss.xml$ rss.php [L]
I am not an expert in these things so it is all try and error. I used this online converter http://winginx.com/htaccess and I got this output:

Code:
# nginx configuration

location = /index.html {
  rewrite ^(.*)$ /index.php;
}

location /browse {
  rewrite ^/browse-(.*)-videos.html$ /category.php?cat=$1;
  rewrite ^/browse-(.*)-videos-([0-9]+)-(.*).html$ /category.php?cat=$1&page=$2&sortby=$3;
}

location = /register.html {
  rewrite ^(.*)$ /register.php;
}

location = /contact_us.html {
  rewrite ^(.*)$ /contact_us.php;
}

location = /edit_profile.html {
  rewrite ^(.*)$ /edit_profile.php;
}

location = /suggest.html {
  rewrite ^(.*)$ /suggest.php;
  rewrite ^(.*)$ /suggest.php;
}

location = /upload.html {
  rewrite ^(.*)$ /upload.php;
}

location = /upload_avatar.html {
  rewrite ^(.*)$ /upload_avatar.php;
}

location /favorites {
  rewrite ^/favorites.html(.*)$ /favorites.php$1;
  rewrite ^/favorites.html(.*)$ /favorites.php$1;
}

location /login {
  rewrite ^/login.html(.*)$ /login.php$1;
}

location /newvideos {
  rewrite ^/newvideos.html(.*)$ /newvideos.php$1;
}

location /topvideos {
  rewrite ^/topvideos.html(.*)$ /topvideos.php$1;
}

location /profile {
  rewrite ^/profile.html(.*)$ /profile.php$1;
}

location /playlist {
  rewrite ^/playlist/(.*)$ /myfavorites.php?u=$1;
}

location /memberlist {
  rewrite ^/memberlist.html(.*)$ /memberlist.php$1;
}

location /articles {
  rewrite ^/articles/read-(.*)_([0-9]+).html$ /article_read.php?a=$2;
  rewrite ^/articles/index-([0-9]+).html$ /article.php?page=$1;
  rewrite ^/articles/browse-(.*)-([0-9]+).html$ /article.php?c=$1&page=$2;
  rewrite ^/articles/tag/([^/]+)/page-([0-9]+)(/)?$ /article.php?tag=$1&page=$2;
  rewrite ^/articles/tag/([^/]+)(/)?$ /article.php?tag=$1&page=1;
  rewrite ^/articles/popular-([0-9]+).html$ /article.php?show=popular&page=$1;
  rewrite ^/articles(\/|.html)?$ /article.php;
}

location /article {
  rewrite ^/article(\/|.html)?$ /article.php;
}

location /pages {
  rewrite ^/pages/(.*)\.html$ /page.php?name=$1;
}

location /tags {
  rewrite ^/tags/([^/]+)/$ /tag.php?t=$1&page=1;
  rewrite ^/tags/([^/]+)/page-([0-9]+)(/)?$ /tag.php?t=$1&page=$2;
}

location / {
  rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;
  rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;
}

location /fpembed {
  rewrite ^/fpembed-(.*).swf$ /fpembed.php?vid=$1;
}

location = /rss.xml {
  rewrite ^(.*)$ /rss.php break;
}
So then from SSH I typed:
nano /etc/nginx/nginx.conf
and pasted the above content under http {
then ran:
/etc/init.d/nginx start
and here is the error message:
Code:
Starting nginx: nginx: [emerg] "location" directive is not allowed here in /etc/nginx/nginx.conf:75
nginx: configuration file /etc/nginx/nginx.conf test failed
Ok so I used another converter located here http://www.anilcetin.com/convert-apa...cess-to-nginx/
its output is:
Code:
	rewrite ^/index.html$ /index.php;
	rewrite ^/browse-(.*)-videos.html$ /category.php?cat=$1;
	rewrite ^/browse-(.*)-videos-([0-9]+)-(.*).html$ /category.php?cat=$1&page=$2&sortby=$3;
	rewrite ^/register.html$ /register.php;
	rewrite ^/contact_us.html$ /contact_us.php;
	rewrite ^/edit_profile.html$ /edit_profile.php;
	rewrite ^/suggest.html$ /suggest.php;
	rewrite ^/upload.html$ /upload.php;
	rewrite ^/upload_avatar.html$ /upload_avatar.php;
	rewrite ^/suggest.html$ /suggest.php;
	rewrite ^/favorites.html(.*)$ /favorites.php$1;
	rewrite ^/login.html(.*)$ /login.php$1;
	rewrite ^/newvideos.html(.*)$ /newvideos.php$1;
	rewrite ^/topvideos.html(.*)$ /topvideos.php$1;
	rewrite ^/profile.html(.*)$ /profile.php$1;
	rewrite ^/favorites.html(.*)$ /favorites.php$1;
	rewrite ^/playlist/(.*)$ /myfavorites.php?u=$1;
	rewrite ^/memberlist.html(.*)$ /memberlist.php$1;
	rewrite ^/articles/read-(.*)_([0-9]+).html$ /article_read.php?a=$2;
	rewrite ^/articles/index-([0-9]+).html$ /article.php?page=$1;
	rewrite ^/articles/browse-(.*)-([0-9]+).html$ /article.php?c=$1&page=$2;
	rewrite ^/articles/tag/([^/]+)/page-([0-9]+)(/)?$ /article.php?tag=$1&page=$2;
	rewrite ^/articles/tag/([^/]+)(/)?$ /article.php?tag=$1&page=1;
	rewrite ^/articles/popular-([0-9]+).html$ /article.php?show=popular&page=$1;
	rewrite ^/articles(/|.html)?$ /article.php;
	rewrite ^/article(/|.html)?$ /article.php;
	rewrite ^/pages/(.*).html$ /page.php?name=$1;
	rewrite ^/tags/([^/]+)/$ /tag.php?t=$1&page=1;
	rewrite ^/tags/([^/]+)/page-([0-9]+)(/)?$ /tag.php?t=$1&page=$2;
	rewrite ^/(.*)/(.*)-video_(.*).html$ /musicvideo.php?vid=$3;
	rewrite ^/([^/]*)-video_(.*).html$ /watch.php?vid=$2;
	rewrite ^/fpembed-(.*).swf$ /fpembed.php?vid=$1;
	rewrite ^/rss.xml$ /rss.php last;
and when I copy this code into nginx conf and start nginx here is what I get:
Code:
Starting nginx: nginx: [emerg] "rewrite" directive is not allowed here in /etc/nginx/nginx.conf:73
nginx: configuration file /etc/nginx/nginx.conf test failed
I am lost! Please anyone tell me what I am doing wrong!!

Thank you for your time..
Reply With Quote
Sponsored Links
  #2  
Old 28th March 2013, 17:08
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You probably copied the rewrite rules to the wrong place. Please post your full vhost configuration (including the rewrite rules from anilcetin).
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 28th March 2013, 17:20
ababneh ababneh is offline
Junior Member
 
Join Date: Mar 2013
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by falko View Post
You probably copied the rewrite rules to the wrong place. Please post your full vhost configuration (including the rewrite rules from anilcetin).
where would that be located?? thank you
Reply With Quote
  #4  
Old 29th March 2013, 02:54
ababneh ababneh is offline
Junior Member
 
Join Date: Mar 2013
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello. Could someone help out even if for $ just let me know.. it is urgent !
Reply With Quote
  #5  
Old 2nd April 2013, 20:21
ababneh ababneh is offline
Junior Member
 
Join Date: Mar 2013
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

grrr why no one said anything about nginx directives in ispconfig. it worked from there.
Reply With Quote
  #6  
Old 5th April 2013, 00:15
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

You didn't mention that you're using ISPConfig.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #7  
Old 5th April 2013, 00:19
ababneh ababneh is offline
Junior Member
 
Join Date: Mar 2013
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
 
Default

I sure did:

Quote:
I installed ispconfig/nginx on ubuntu 12.10 following your great how-to:

http://www.howtoforge.com/perfect-se...ispconfig-3-p4
it is all good now though.

Cheers
Reply With Quote
Reply

Bookmarks

Tags
nginx, rewrite

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apche rewrite rule convert to nginx nerijussk Server Operation 3 26th November 2012 18:15
500 Internal Server Error BoloMarkIII Installation/Configuration 4 21st October 2010 16:56
Forbidden 403; Samba access; config of maildeamon fawkes Installation/Configuration 4 14th January 2010 18:16
Yet Another Internal Server Error/.htaccess Post n0h4t Installation/Configuration 5 16th June 2009 17:43
ispconfig and mambo shajazzi Installation/Configuration 70 28th March 2006 19:29


All times are GMT +2. The time now is 06:54.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.