簡體   English   中英

htaccess重寫為Nginx錯誤

[英]htaccess rewrite to nginx bugs

我在舊的.htaccess文件中有此代碼

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([a-z0-9]+) [NC]
RewriteRule ^ %1/%2/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)/?$ /index.php?page=$1 [L,NC]

並且我最近已升級到nginx,並且在我的配置中使用了以下代碼,而不是Apache重寫規則。

rewrite ^/(.*)$ /index.php?page=$1$args? last;

這也可以正常工作,但是當我嘗試在/Style/Main.css中加載樣式表時,它會嘗試將文件作為get請求加載。 如何解決此問題,使其無法執行此操作?

在將請求的URL傳遞給重寫之前,您需要一個try_files來檢查所請求的URL(在您的情況下為css,js等)是否存在。 嘗試類似:

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^/(.*)$ /index.php?page=$1$args? last;
}

暫無
暫無

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

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