2017-09-23 202 views
0

我是新來nginx的,我不知道如何使用的.htaccess nginx的,哪裏放置生成的代碼在nginx的configuration.could請人幫我將它轉換爲nginx的?如何在nginx中使用.htaccess以及在哪裏放置它?

這裏是我的.htaccess文件

<IfModule mod_rewrite.c> 

RewriteCond ${REQUEST_URI} ^.+$ 
RewriteCond %{REQUEST_FILENAME} \.(admin)$ [OR] 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -l 
RewriteRule^- [L] 
RewriteCond %{QUERY_STRING} [^a-z](cast|char|convert|declare|delete|drop|exec|insert|meta|script|select|set|truncate|update)[^a-z] [NC] 
RewriteRule (.*) - [F] 
RewriteEngine On 
# redirect with username 
Options +FollowSymLinks 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(admin|assets|include)(.*)?$ /$1$2 [L,QSA,R=301] 
RewriteRule ^user/([a-zA-Z0-9_-]+)$ user.php?username=$1 
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ user.php?username=$1 
RewriteRule ^media/([a-zA-Z0-9_-]+)$ media.php?id=$1 
RewriteRule ^media/([a-zA-Z0-9_-]+)/$ media.php?id=$1 
RewriteRule ^tag/([^/.]+)$ tag.php?tag=$1 [QSA,L] 
RewriteRule ^tag/([^/.]+)/$ tag.php?tag=$1 [QSA,L] 
# turn on the mod_rewrite engine 
RewriteCond %{REQUEST_FILENAME}.php -f 
# IF the request filename with .php extension is a file which exists 
RewriteCond %{REQUEST_URI} !/$ 
# AND the request is not for a directory 
RewriteRule (.*) $1\.php [L] 
# redirect to the php script with the requested filename 



</IfModule> 

請幫我將它轉換爲nginx的,引導我在哪裏正是把這個代碼。謝謝!

+0

nginx的不使用(讀)的.htaccess,只與Apache – Mark

+0

是的,但有一種方法來轉換htaccess的nginx的吧? –

回答

0

Nginx的不使用htaccess的文件;你必須指定的規則在Nginx的站點配置說,/etc/nginx/sites-enabled/my-site.com.conf。你可以使用服務像this爲您現有htaccess文件轉換爲Nginx的構形,但轉換後,你必須重新檢查如果有什麼是錯的。

下面是從CONF以上服務轉化爲獲取所需的配置改變一些想法,但可能會有一些變化與您當前nginx的配置。

location ~ \.(admin)$ { 
} 
location ~ /$ { 
} 
location/{ 
if ($query_string ~* "[^a-z](cast|char|convert|declare|delete|drop|exec|insert|meta|script|select|set|truncate|update)[^a-z]"){ 
    return 403; 
} 
if (!-e $request_filename){ 
     rewrite ^/(admin|assets|include)(.*)?$ /$1$2 redirect; 
    } 
    rewrite ^(.*)$ /$1\.php break; 
} 
location /user { 
    rewrite ^/user/([a-zA-Z0-9_-]+)$ /user.php?username=$1; 
    rewrite ^/user/([a-zA-Z0-9_-]+)/$ /user.php?username=$1; 
} 
location /media { 
     rewrite ^/media/([a-zA-Z0-9_-]+)$ /media.php?id=$1; 
     rewrite ^/media/([a-zA-Z0-9_-]+)/$ /media.php?id=$1; 
} 
location /tag { 
    rewrite ^/tag/([^/.]+)$ /tag.php?tag=$1 break; 
    rewrite ^/tag/([^/.]+)/$ /tag.php?tag=$1 break; 
} 
+0

我的/ etc/nginx/sites-enabled /文件夾中沒有任何內容爲空。我在/ etc/nginx/sites中添加了服務器配置 - 可用的操作? –

+0

你可以用'LN -s /etc/sites-available/foo.com.conf的/ etc /啓用站點-/ foo.com.conf'然後使用重新加載nginx的'須藤的nginx -s reload'符號鏈接 –

相關問題