M0rtiis
M0rtiis

Reputation: 3784

'nginx rewrite' to '.htacces rewrite'

Im very bad in regexps, but in server-configs im the worst. So any help ll be usefull.

have such in nginx-config

location / {
    rewrite ^(.*[^/])$ $1/ permanent;
    try_files $uri $uri/ /index.php?$args;
}

need EQUAL thing for .htacces. Ty.

Upvotes: 0

Views: 68

Answers (1)

SimpleAnecdote
SimpleAnecdote

Reputation: 775

They should prove very similar.

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Your web directory root
    RewriteBase /

    #Make sure it's not a specific file or directory that they're trying to reach
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d

    RewriteRule ^(.*[^/])$ index.php?args=$1 [NC, L]
</IfModule>

This will:

  1. Mark RewriteEngine on for the folder the .htaccess is in (if you've got the module enabled);
  2. Specify conditions to avoid redirection if the file is a directory or a file on the server; And
  3. Redirect your Regex to index.php?args={everything caught by the regex}

The [NC, L] flags tell the rule to be not case sensitive and tell Apache this is the last redirection rule, respectively.

I have to admit, I'm not sure what your Regex is testing for though. Would you mind explaining the URL scheme you want to put in place? I should be able to help you formulate the Regex properly.

Upvotes: 1

Related Questions