0
I am trying to convert some htaccess rules to NGINX and am getting ERR_TOO_MANY_REDIRECTS.
The htaccess code is this https://pastebin.com/UwGnNybj
Options +FollowSymLinks -MultiViews
# Secuirty Control
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|tpl)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# Cache Control
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
# Gzip Control
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE image/jpg
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/javascript
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L,QSA]
# Installer
RewriteRule ^install/?$ install.php [L,QSA]
# Static Pages
RewriteRule ^static/([^/]+)/?$ static.php?url=$1 [L,QSA]
# Contacts
RewriteRule ^contacts/?$ contact.php [L,QSA]
# Directory
RewriteRule ^directory/?$ directory.php [L,QSA]
RewriteRule ^directory/([^/]+)/?$ directory.php?view=$1 [L,QSA]
RewriteRule ^directory/([^/]+)/([^/]+)/?$ directory.php?view=$1&page=$2 [L,QSA]
# Search
RewriteRule ^search/?$ search.php [L,QSA]
RewriteRule ^search/hashtag/([^/]+)/?$ search.php?query=$1&hashtag=1 [L,QSA]
RewriteRule ^search/([^/]+)/?$ search.php?query=$1&hashtag=0 [L,QSA]
# Sign(in|up|out)
RewriteRule ^signin/?$ sign.php?do=in [L,QSA]
RewriteRule ^signup/?$ sign.php?do=up [L,QSA]
RewriteRule ^signout/?$ sign.php?do=out [L,QSA]
RewriteRule ^reset/?$ sign.php?do=reset [L,QSA]
RewriteRule ^activation/([^/]+)/([^/]+)/?$ activation.php?id=$1&token=$2 [L,QSA]
# Social Logins
RewriteRule ^connect/([^/]+)/?$ connect.php?do=connect&provider=$1 [L,QSA]
RewriteRule ^revoke/([^/]+)/?$ connect.php?do=revoke&provider=$1 [L,QSA]
# Packages
RewriteRule ^packages/?$ packages.php [L,QSA]
# Started
RewriteRule ^started/?$ started.php [L,QSA]
RewriteRule ^started/finished?$ started.php?finished=true [L,QSA]
# Messages
RewriteRule ^messages/?$ messages.php [L,QSA]
RewriteRule ^messages/new?$ messages.php?view=new [L,QSA]
RewriteRule ^messages/([^/]+)/?$ messages.php?cid=$1 [L,QSA]
# Notifications
RewriteRule ^notifications/?$ notifications.php [L,QSA]
# Settings
RewriteRule ^settings/?$ settings.php [L,QSA]
RewriteRule ^settings/([^/]+)/?$ settings.php?view=$1 [L,QSA]
# Posts & Photos
RewriteRule ^posts/([^/]+)/?$ post.php?post_id=$1 [L,QSA]
RewriteRule ^photos/([^/]+)/?$ photo.php?photo_id=$1 [L,QSA]
# Saved
RewriteRule ^saved/?$ index.php?view=saved [L,QSA]
# Ads
RewriteRule ^ads/?$ ads.php [L,QSA]
RewriteRule ^ads/new?$ ads.php?view=new [L,QSA]
RewriteRule ^ads/edit/([^/]+)/?$ ads.php?view=edit&campaign_id=$1 [L,QSA]
RewriteRule ^wallet/?$ ads.php?view=wallet [L,QSA]
# Boosted
RewriteRule ^boosted/posts/?$ index.php?view=boosted_posts [L,QSA]
RewriteRule ^boosted/pages/?$ index.php?view=boosted_pages [L,QSA]
# People
RewriteRule ^people/?$ people.php [L,QSA]
RewriteRule ^people/find/?$ people.php?view=find [L,QSA]
RewriteRule ^people/friend_requests/?$ people.php?view=friend_requests [L,QSA]
RewriteRule ^people/sent_requests/?$ people.php?view=sent_requests [L,QSA]
# Pages
RewriteRule ^pages/?$ pages.php [L,QSA]
RewriteRule ^pages/liked/?$ pages.php?view=liked [L,QSA]
RewriteRule ^pages/manage/?$ pages.php?view=manage [L,QSA]
RewriteRule ^pages/([^/]+)/?$ page.php?username=$1 [L,QSA]
RewriteRule ^pages/([^/]+)/([^/]+)/?$ page.php?username=$1&view=$2 [L,QSA]
RewriteRule ^pages/([^/]+)/([^/]+)/([^/]+)/?$ page.php?username=$1&view=$2&id=$3 [L,QSA]
# Groups
RewriteRule ^groups/?$ groups.php [L,QSA]
RewriteRule ^groups/joined/?$ groups.php?view=joined [L,QSA]
RewriteRule ^groups/manage/?$ groups.php?view=manage [L,QSA]
RewriteRule ^groups/([^/]+)/?$ group.php?username=$1 [L,QSA]
RewriteRule ^groups/([^/]+)/([^/]+)/?$ group.php?username=$1&view=$2 [L,QSA]
RewriteRule ^groups/([^/]+)/([^/]+)/([^/]+)/?$ group.php?username=$1&view=$2&id=$3 [L,QSA]
# Events
RewriteRule ^events/?$ events.php [L,QSA]
RewriteRule ^events/going/?$ events.php?view=going [L,QSA]
RewriteRule ^events/interested/?$ events.php?view=interested [L,QSA]
RewriteRule ^events/invited/?$ events.php?view=invited [L,QSA]
RewriteRule ^events/manage/?$ events.php?view=manage [L,QSA]
RewriteRule ^events/([^/]+)/?$ event.php?event_id=$1 [L,QSA]
RewriteRule ^events/([^/]+)/([^/]+)/?$ event.php?event_id=$1&view=$2 [L,QSA]
RewriteRule ^events/([^/]+)/([^/]+)/([^/]+)/?$ event.php?event_id=$1&view=$2&id=$3 [L,QSA]
# Forums
RewriteRule ^forums/?$ forums.php [L,QSA]
RewriteRule ^forums/my-threads/?$ forums.php?view=my-threads [L,QSA]
RewriteRule ^forums/my-replies/?$ forums.php?view=my-replies [L,QSA]
RewriteRule ^forums/search/?$ forums.php?view=search [L,QSA]
RewriteRule ^forums/search-results/?$ forums.php?view=search-results [L,QSA]
RewriteRule ^forums/new-thread/([^/]+)/?$ forums.php?view=new-thread&forum_id=$1 [L,QSA]
RewriteRule ^forums/edit-thread/([^/]+)/?$ forums.php?view=edit-thread&thread_id=$1 [L,QSA]
RewriteRule ^forums/new-reply/([^/]+)/?$ forums.php?view=new-reply&thread_id=$1 [L,QSA]
RewriteRule ^forums/edit-reply/([^/]+)/?$ forums.php?view=edit-reply&reply_id=$1 [L,QSA]
RewriteRule ^forums/thread/([^/]+)/([^/]+)/?$ forums.php?view=thread&thread_id=$1 [L,QSA]
RewriteRule ^forums/([^/]+)/([^/]+)/?$ forums.php?view=forum&forum_id=$1 [L,QSA]
# Blogs
RewriteRule ^articles/?$ index.php?view=articles [L,QSA]
RewriteRule ^blogs/?$ blogs.php [L,QSA]
RewriteRule ^blogs/new/?$ blogs.php?view=new [L,QSA]
RewriteRule ^blogs/edit/([^/]+)/?$ blogs.php?view=edit&post_id=$1 [L,QSA]
RewriteRule ^blogs/category/([^/]+)/([^/]+)/?$ blogs.php?view=category&category_id=$1 [L,QSA]
RewriteRule ^blogs/([^/]+)/([^/]+)/?$ blogs.php?view=article&post_id=$1 [L,QSA]
# Market
RewriteRule ^products/?$ index.php?view=products [L,QSA]
RewriteRule ^market/?$ market.php [L,QSA]
RewriteRule ^market/search/?$ market.php?view=search [L,QSA]
RewriteRule ^market/search/([^/]+)/?$ market.php?view=search&query=$1 [L,QSA]
RewriteRule ^market/search/([^/]+)/([^/]+)/?$ market.php?view=search&query=$1&page=$2 [L,QSA]
RewriteRule ^market/category/([^/]+)/?$ market.php?view=category&category_id=$1 [L,QSA]
RewriteRule ^market/category/([^/]+)/([^/]+)/?$ market.php?view=category&category_id=$1&category_url=$2 [L,QSA]
RewriteRule ^market/category/([^/]+)/([^/]+)/([^/]+)/?$ market.php?view=category&category_id=$1&category_url=$2&page=$3 [L,QSA]
RewriteRule ^market/([^/]+)/?$ market.php?page=$1 [L,QSA]
# Games
RewriteRule ^games/?$ games.php [L,QSA]
RewriteRule ^games/played/?$ games.php?view=played [L,QSA]
RewriteRule ^games/([^/]+)/?$ game.php?id=$1 [L,QSA]
# Admin Panel
RewriteRule ^admincp/?$ admin.php [L,QSA]
RewriteRule ^admincp/([^/]+)/?$ admin.php?view=$1 [L,QSA]
RewriteRule ^admincp/([^/]+)/([^/]+)/?$ admin.php?view=$1&sub_view=$2 [L,QSA]
RewriteRule ^admincp/([^/]+)/([^/]+)/([^/]+)/?$ admin.php?view=$1&sub_view=$2&id=$3 [L,QSA]
# Profile
RewriteRule ^([^/]+)/?$ profile.php?username=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ profile.php?username=$1&view=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ profile.php?username=$1&view=$2&id=$3 [L,QSA]
The code I converted using https://winginx.com/en/htaccess and the code I implemented in my Docker container is this https://pastebin.com/y1qMEzUw
server {
index index.php;
listen 80;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code-admin;
location / {
if (-e $request_filename){
rewrite ^/install/?$ /install.php last;
}
rewrite ^/([^/]+)/?$ /profile.php?username=$1 last;
rewrite ^/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2 last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2&id=$3 last;
}
location /static {
rewrite ^/static/([^/]+)/?$ /static.php?url=$1 last;
}
location /contacts {
rewrite ^/contacts/?$ /contact.php last;
}
location /directory {
rewrite ^/directory/?$ /directory.php last;
rewrite ^/directory/([^/]+)/?$ /directory.php?view=$1 last;
rewrite ^/directory/([^/]+)/([^/]+)/?$ /directory.php?view=$1&page=$2 last;
}
location /search {
rewrite ^/search/?$ /search.php last;
rewrite ^/search/hashtag/([^/]+)/?$ /search.php?query=$1&hashtag=1 last;
rewrite ^/search/([^/]+)/?$ /search.php?query=$1&hashtag=0 last;
}
location /signin {
rewrite ^/signin/?$ /sign.php?do=in last;
}
location /signup {
rewrite ^/signup/?$ /sign.php?do=up last;
}
location /signout {
rewrite ^/signout/?$ /sign.php?do=out last;
}
location /reset {
rewrite ^/reset/?$ /sign.php?do=reset last;
}
location /activation {
rewrite ^/activation/([^/]+)/([^/]+)/?$ /activation.php?id=$1&token=$2 last;
}
location /connect {
rewrite ^/connect/([^/]+)/?$ /connect.php?do=connect&provider=$1 last;
}
location /revoke {
rewrite ^/revoke/([^/]+)/?$ /connect.php?do=revoke&provider=$1 last;
}
location /packages {
rewrite ^/packages/?$ /packages.php last;
}
location /started {
rewrite ^/started/?$ /started.php last;
rewrite ^/started/finished?$ /started.php?finished=true last;
}
location /messages {
rewrite ^/messages/?$ /messages.php last;
rewrite ^/messages/new?$ /messages.php?view=new last;
rewrite ^/messages/([^/]+)/?$ /messages.php?cid=$1 last;
}
location /notifications {
rewrite ^/notifications/?$ /notifications.php last;
}
location /settings {
rewrite ^/settings/?$ /settings.php last;
rewrite ^/settings/([^/]+)/?$ /settings.php?view=$1 last;
}
location /posts {
rewrite ^/posts/([^/]+)/?$ /post.php?post_id=$1 last;
}
location /photos {
rewrite ^/photos/([^/]+)/?$ /photo.php?photo_id=$1 last;
}
location /saved {
rewrite ^/saved/?$ /index.php?view=saved last;
}
location /ads {
rewrite ^/ads/?$ /ads.php last;
rewrite ^/ads/new?$ /ads.php?view=new last;
rewrite ^/ads/edit/([^/]+)/?$ /ads.php?view=edit&campaign_id=$1 last;
}
location /wallet {
rewrite ^/wallet/?$ /ads.php?view=wallet last;
}
location /boosted {
rewrite ^/boosted/posts/?$ /index.php?view=boosted_posts last;
rewrite ^/boosted/pages/?$ /index.php?view=boosted_pages last;
}
location /people {
rewrite ^/people/?$ /people.php last;
rewrite ^/people/find/?$ /people.php?view=find last;
rewrite ^/people/friend_requests/?$ /people.php?view=friend_requests last;
rewrite ^/people/sent_requests/?$ /people.php?view=sent_requests last;
}
location /pages {
rewrite ^/pages/?$ /pages.php last;
rewrite ^/pages/liked/?$ /pages.php?view=liked last;
rewrite ^/pages/manage/?$ /pages.php?view=manage last;
rewrite ^/pages/([^/]+)/?$ /page.php?username=$1 last;
rewrite ^/pages/([^/]+)/([^/]+)/?$ /page.php?username=$1&view=$2 last;
rewrite ^/pages/([^/]+)/([^/]+)/([^/]+)/?$ /page.php?username=$1&view=$2&id=$3 last;
}
location /groups {
rewrite ^/groups/?$ /groups.php last;
rewrite ^/groups/joined/?$ /groups.php?view=joined last;
rewrite ^/groups/manage/?$ /groups.php?view=manage last;
rewrite ^/groups/([^/]+)/?$ /group.php?username=$1 last;
rewrite ^/groups/([^/]+)/([^/]+)/?$ /group.php?username=$1&view=$2 last;
rewrite ^/groups/([^/]+)/([^/]+)/([^/]+)/?$ /group.php?username=$1&view=$2&id=$3 last;
}
location /events {
rewrite ^/events/?$ /events.php last;
rewrite ^/events/going/?$ /events.php?view=going last;
rewrite ^/events/interested/?$ /events.php?view=interested last;
rewrite ^/events/invited/?$ /events.php?view=invited last;
rewrite ^/events/manage/?$ /events.php?view=manage last;
rewrite ^/events/([^/]+)/?$ /event.php?event_id=$1 last;
rewrite ^/events/([^/]+)/([^/]+)/?$ /event.php?event_id=$1&view=$2 last;
rewrite ^/events/([^/]+)/([^/]+)/([^/]+)/?$ /event.php?event_id=$1&view=$2&id=$3 last;
}
location /forums {
rewrite ^/forums/?$ /forums.php last;
rewrite ^/forums/my-threads/?$ /forums.php?view=my-threads last;
rewrite ^/forums/my-replies/?$ /forums.php?view=my-replies last;
rewrite ^/forums/search/?$ /forums.php?view=search last;
rewrite ^/forums/search-results/?$ /forums.php?view=search-results last;
rewrite ^/forums/new-thread/([^/]+)/?$ /forums.php?view=new-thread&forum_id=$1 last;
rewrite ^/forums/edit-thread/([^/]+)/?$ /forums.php?view=edit-thread&thread_id=$1 last;
rewrite ^/forums/new-reply/([^/]+)/?$ /forums.php?view=new-reply&thread_id=$1 last;
rewrite ^/forums/edit-reply/([^/]+)/?$ /forums.php?view=edit-reply&reply_id=$1 last;
rewrite ^/forums/thread/([^/]+)/([^/]+)/?$ /forums.php?view=thread&thread_id=$1 last;
rewrite ^/forums/([^/]+)/([^/]+)/?$ /forums.php?view=forum&forum_id=$1 last;
}
location /articles {
rewrite ^/articles/?$ /index.php?view=articles last;
}
location /blogs {
rewrite ^/blogs/?$ /blogs.php last;
rewrite ^/blogs/new/?$ /blogs.php?view=new last;
rewrite ^/blogs/edit/([^/]+)/?$ /blogs.php?view=edit&post_id=$1 last;
rewrite ^/blogs/category/([^/]+)/([^/]+)/?$ /blogs.php?view=category&category_id=$1 last;
rewrite ^/blogs/([^/]+)/([^/]+)/?$ /blogs.php?view=article&post_id=$1 last;
}
location /products {
rewrite ^/products/?$ /index.php?view=products last;
}
location /market {
rewrite ^/market/?$ /market.php last;
rewrite ^/market/search/?$ /market.php?view=search last;
rewrite ^/market/search/([^/]+)/?$ /market.php?view=search&query=$1 last;
rewrite ^/market/search/([^/]+)/([^/]+)/?$ /market.php?view=search&query=$1&page=$2 last;
rewrite ^/market/category/([^/]+)/?$ /market.php?view=category&category_id=$1 last;
rewrite ^/market/category/([^/]+)/([^/]+)/?$ /market.php?view=category&category_id=$1&category_url=$2 last;
rewrite ^/market/category/([^/]+)/([^/]+)/([^/]+)/?$ /market.php?view=category&category_id=$1&category_url=$2&page=$3 last;
rewrite ^/market/([^/]+)/?$ /market.php?page=$1 last;
}
location /games {
rewrite ^/games/?$ /games.php last;
rewrite ^/games/played/?$ /games.php?view=played last;
rewrite ^/games/([^/]+)/?$ /game.php?id=$1 last;
}
location /admincp {
rewrite ^/admincp/?$ /admin.php last;
rewrite ^/admincp/([^/]+)/?$ /admin.php?view=$1 last;
rewrite ^/admincp/([^/]+)/([^/]+)/?$ /admin.php?view=$1&sub_view=$2 last;
rewrite ^/admincp/([^/]+)/([^/]+)/([^/]+)/?$ /admin.php?view=$1&sub_view=$2&id=$3 last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Probably somewhere is having a redirect loop, kind of url
/foo
to the/bar
and of/bar
to the/foo
, hence this error. Note, at all times put the code here on the site, not just links– Costamilam
Thank you William, I put the code embedded here, but even looking for what you quoted, I still can’t find.
– ericrj