wordpress 在linux上配置固定url方法

來源:互聯網
上載者:User

標籤:

wordpress 設定固定url總結

相信好多用wordpress的網友為了提升wordpress對搜尋引擎的友好,或者是為了寫的部落格地址更好記,都會在wordpress的後台設定固定url的方式。

但問題來了,一開始wordpress預設的url是用網域名稱加?p=id的方式的。改了後就出來404頁面

我們來百度下吧,不知道就搜尋呀,得到結果如下

通過在Apache設定檔httpd.conf中找到LoadModule rewrite_module modules/mod_rewrite.so  將其前面的注釋#去掉,然後重啟伺服器,問題就解決了。

下面說下在nginx下的設定,在nginx的網站設定檔中加入下面的代碼

location / {if (-f $request_filename/index.html){                rewrite (.*) $1/index.html break;        }if (-f $request_filename/index.php){                rewrite (.*) $1/index.php;        }if (!-f $request_filename){                rewrite (.*) /index.php;        }}

但是我的伺服器上的nginx有一個預設wordpress的規則檔案(這個檔案不保證所有nginx下都能用,自己測試吧)

wordpress.conf

location /blog/ {        try_files $uri $uri/ /blog/index.php?$args;}# Add trailing slash to */wp-admin requests.rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

在nginx的網站設定檔中將這個wordpress.conf引入

如 /usr/localhost/nginx/conf/vhost/blog.conf

blog.conf就是我的nginx上的網站設定檔

這個檔案中加入

include wordpress.conf;

重啟lnmp現在還是404

問題出在,我是以wordpress作為根目錄而wordpress的規則應該是按照根目錄下的/blog檔案夾這樣的網站配置路徑來寫的

所以wordpress.conf應該改為

location / {        try_files $uri $uri/ /index.php?$args;}# Add trailing slash to */wp-admin requests.rewrite /wp-admin$ $scheme://$host$uri/ permanent;

再重啟服務,問題解決

wordpress 在linux上配置固定url方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.