简体   繁体   中英

'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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM