Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Need some help please converting htaccess to Nginx Rewrite

$
0
0
so I'm trying to convert this Apache .htaccess to Nginx, I already tried with online converters but the news, list, video, music, polls and quiz sections are working they give 404

here the Apache .htaccess that I want to convert:

if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/$ /index.php?link1=home;
}
rewrite ^/news/(.*)$ /index.php?link1=news&id=$1;
rewrite ^/lists/(.*)$ /index.php?link1=lists&id=$1;
rewrite ^/polls/(.*)$ /index.php?link1=polls&id=$1;
rewrite ^/quiz/(.*)$ /index.php?link1=quiz&id=$1;
rewrite ^/videos/(.*)$ /index.php?link1=videos&id=$1;
rewrite ^/music/(.*)$ /index.php?link1=music&id=$1;
rewrite ^/edit-post/(.*)$ /index.php?link1=edit-post&id=$1;
rewrite ^/delete-post/(.*)$ /index.php?link1=delete-post&id=$1;
rewrite ^/settings/(.*)/(.*)$ /index.php?link1=settings&page=$1&user=$2;
rewrite ^/settings/(.*)$ /index.php?link1=settings&page=$1;
rewrite ^/admin-cp$ /admincp.php;
rewrite ^/admin-cp/(.*)$ /admincp.php?page=$1;
rewrite ^/admincp/(.*)$ /index.php?link1=admincp&page=$1;
rewrite ^/admin-cdn/(.*)$ /admin-panel/$1 last;
rewrite ^/tags/(.*)$ /index.php?link1=tags&tag=$1;
rewrite ^/feeds/rss(/?|)$ /index.php?link1=feeds&page=home;
rewrite ^/post_data/(.*)/(.*)(/?|)$ /index.php?link1=post_data&post_type=$1&id=$2;
rewrite ^/terms/(.*)$ /index.php?link1=terms&type=$1;
rewrite "^/go_pro(?:\/{0,1}|)$" /index.php?link1=go_pro;
rewrite ^/latest-(.*)/(\d+)$ /index.php?link1=latest-$1&c_id=$2;
rewrite ^/latest-(.*)/rss(/?|)$ /index.php?link1=rss&page=$1;
rewrite ^/ads(?:\/?|)$ /index.php?link1=ads;
rewrite ^/ads/create-new(?:\/?|)$ /index.php?link1=create_ad;
rewrite ^/ads/edit/([0-9]+)(?:\/?|)$ /index.php?link1=edit_ad&ad_id=$1;
if (!-f $request_filename){
set $rule_25 1$rule_25;
}
if (!-d $request_filename){
set $rule_25 2$rule_25;
}
if ($rule_25 = "21"){
rewrite ^/@([^\/]+)(\/|)$ /;
}
rewrite ^/@([^\/]+)(\/|)/(.*)$ /;
if (!-f $request_filename){
set $rule_27 1$rule_27;
}
if (!-d $request_filename){
set $rule_27 2$rule_27;
}
if ($rule_27 = "21"){
rewrite ^/([^\/]+)(\/|)$ /;
}




and this is the converted Nginx automatically converted. (this is my first time with Nginx so the editions I made to the auto-converted code where according to 2 hours Nginx knowledge reading the docs) tool used to convert https://www.winginx.com/en/htaccess


location / {
if (!-e $request_filename){
rewrite ^/$ /index.php?link1=home;
}
rewrite "^/go_pro(?:\/{0,1}|)$" /index.php?link1=go_pro;
if (!-e $request_filename){
rewrite ^/@([^\/]+)(\/|)$ /index.php?link1=profile&u=$1;
}
rewrite ^/@([^\/]+)(\/|)/(.*)$ /index.php?link1=profile&u=$1&page=$2;
if (!-e $request_filename){
rewrite ^/([^\/]+)(\/|)$ /index.php?link1=$1;
}
}


***(not working from here and below news, list, video, music, polls and quiz sections)***

location /news {
rewrite ^/news/(.*)$ /index.php?link1=news&id=$1;
}

location /lists {
rewrite ^/lists/(.*)$ /index.php?link1=lists&id=$1;
}

location /polls {
rewrite ^/polls/(.*)$ /index.php?link1=polls&id=$1;
}

location /quiz {
rewrite ^/quiz/(.*)$ /index.php?link1=quiz&id=$1;
}

location /videos {
rewrite ^/videos/(.*)$ /index.php?link1=videos&id=$1;
}

location /music {
rewrite ^/music/(.*)$ /index.php?link1=music&id=$1;
}

location /edit {
rewrite ^/edit-post/(.*)$ /index.php?link1=edit-post&id=$1;
}

location /delete {
rewrite ^/delete-post/(.*)$ /index.php?link1=delete-post&id=$1;
}

location /settings {
rewrite ^/settings/(.*)/(.*)$ /index.php?link1=settings&page=$1&user=$2;
rewrite ^/settings/(.*)$ /index.php?link1=settings&page=$1;
}

***(admin panel and the other admin, term, ads, latest,tags and feed and all rest sections below this line work fine)***

location /admin {
rewrite ^/admin-cp$ /admincp.php;
rewrite ^/admin-cp/(.*)$ /admincp.php?page=$1;
}

location /admincp {
rewrite ^/admincp/(.*)$ /index.php?link1=admincp&page=$1;
}

location /admin-cdn/ {
alias /admin-panel/;
}

location /tags {
rewrite ^/tags/(.*)$ /index.php?link1=tags&tag=$1;
}

location /feeds {
rewrite ^/feeds/rss(/?|)$ /index.php?link1=feeds&page=home;
}

location /post_data {
rewrite ^/post_data/(.*)/(.*)(/?|)$ /index.php?link1=post_data&post_type=$1&id=$2;
}

location /terms {
rewrite ^/terms/(.*)$ /index.php?link1=terms&type=$1;
}

location /latest {
rewrite ^/latest-(.*)/(\d+)$ /index.php?link1=latest-$1&c_id=$2;
rewrite ^/latest-(.*)/rss(/?|)$ /index.php?link1=rss&page=$1;
}

location /ads {
rewrite ^/ads(?:\/?|)$ /index.php?link1=ads;
rewrite ^/ads/create-new(?:\/?|)$ /index.php?link1=create_ad;
rewrite ^/ads/edit/([0-9]+)(?:\/?|)$ /index.php?link1=edit_ad&ad_id=$1;

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>