0

I've read lots of threads here and in other community forums, also tried some htaccess to nginx generators, but I'm struck with this.

Thats my .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !(/$|\.) 
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . index.php [L]
</IfModule>

And here's my nginx configuration:

location / {
  rewrite ^(.*)$ /$request_uri/ redirect;
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
  }
}

When I run my script I'm being redirected in a loop

http://127.0.0.1////////////////////video/tkOVwe1x49C8wgi////////////////////

Will glad to get any help about this!

Dereckkkk
  • 1
  • 1

1 Answers1

1

While converting your first RewriteRule:

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

you completely ignore the condition: don't rewrite anything already ending with / or containing a . (whatever purpose the second condition could have). You can rewrite it using a location block:

location ~ ^[^\.]*[^\./]$ {
    # No leading '/' like in the Apache rule
    return 301 $uri/;
    # rewrite (.*) $uri/ permanent;
    # has the same effect
}

As already remarked by womble and Richard, the second condition should be converted using try_files.

Altogether your rewrite rules should be:

location ~ ^[^\.]*[^\./]$ {
    return 301 $uri/;
}

location / {
    try_files $uri $uri/ index.php;
}
Piotr P. Karwasz
  • 5,292
  • 2
  • 9
  • 20
  • 1
    "whatever purpose the second condition could have" - I think the idea there is to avoid URLs that _look-like_ requests for files (ie. contain a file extension). – MrWhite Mar 03 '20 at 00:11