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/local/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;再重啟服務,問題解決
新聞熱點
疑難解答