簡體   English   中英

從'nginx rewrite'到'.htacces rewrite'

[英]'nginx rewrite' to '.htacces rewrite'

我在正則表達式中非常糟糕,但在服務器配置中最糟糕。 因此,任何幫助都將是有用的。

在nginx-config中有這樣的

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

需要等價的東西。 TY。

他們應該證明非常相似。

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

這將:

  1. 將.htaccess所在的文件夾標記為RewriteEngine(如果已啟用模塊);
  2. 如果文件是服務器上的目錄或文件,請指定避免重定向的條件;
  3. 將您的Regex重定向到index.php?args = {regex捕獲的所有內容}

[NC,L]標志分別告訴該規則區分大小寫,並告訴Apache這是最后一個重定向規則。

我不得不承認,我不確定您的Regex正在測試什么。 您介意解釋要設置的URL方案嗎? 我應該能夠幫助您正確制定正則表達式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM