簡體   English   中英

如何為WordPress重寫NGINX的特定頁面

[英]How to NGINX Rewrite SPECIFIC PAGE for Wordpress

因此,我嘗試做一些獨特的事情,花了幾個小時閱讀有關NGINX重寫以及如何為特定頁面創建CATCH ALL的信息。

我想做的事:

mysite.com/Subdivision/是一個WordPress頁面。

我希望能夠隨機生成(TAIL PAGES),默認情況下,所有這些都將轉到“上層wordpress”頁面(mysite.com/Subdivision/):

mysite.com/Subdivision/Green-Trails
mysite.com/Subdivision/River-Oaks
mysite.com/Subdivision/Creek-Plantation

然后,在我的/ Subdivision /頁面中,我將編寫腳本來告訴它如何使用“綠色小徑”,“河橡樹”和“小溪種植園”

在此之后,目標是還要添加其他內容,例如

mysite.com/Subdivision/Green-Trails/4-bdr/with-pool/

並且我的“ /細分”頁面將在請求URI中找到設置“ IF 4-bdr”,請進行設置。 如果在請求URI中找到with-pool,則設置此...所有操作都將在PHP代碼段中完成。

只需克服NGINX的編寫障礙。

這是我當前使用NGINX的Centmin設置:

    ## BEGIN WORDPRESS MOD ##
index index.php index.html index.htm;
        # enforce www (exclude certain subdomains)
        if ($host !~* ^(www|subdomain))
        {
            #    rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
        }
        # enforce NO www if ($host ~* ^www\.(.*)) {
        #       set $host_without_www $1; rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        #}


        # unless the request is for a valid file, send to bootstrap
        if (!-e $request_filename)
        {
                rewrite ^(.+)$ /index.php?q=$1 last;
        }


location ~ /subdivision/(.*) {
    index index.php;
    try_files $uri /index.php?q=/subdivision/&$args;
}

  location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass localhost:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

## END WORDPRESS MOD ##

如您所見:

location ~ /subdivision/(.*) {
    index index.php;
    try_files $uri /index.php?q=/subdivision/&$args;
}

`

我在這里嘗試告訴NGINX保留/ Subdivision /頁面變量以供wordpress並告訴Wordpress忽略其余URL / Green-Trails / / River-Oaks /,/ Creek-Plantation /

但這不起作用,有人可以幫我嗎,我在哪里錯過了?

問題是WordPress不使用查詢字符串來確定要顯示的頁面,而是直接從REQUEST_URI獲取信息,該信息通常設置為原始URI(在執行任何內部重寫之前)。

簡單的解決方案是執行外部重定向,但這將更改URI出現在瀏覽器中的位置。

可以通過顯式設置SCRIPT_FILENAME和REQUEST_URI來實現所需的目標:

location ^~ /subdivision/ {
    include fastcgi_params;
    fastcgi_pass localhost:9000;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param REQUEST_URI     /Subdivision/;
}

暫無
暫無

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

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