wordpress rewrite nginx
6:55 am, May 4, 2018
this is all you need to get the rewrite working in wordpress and nginx
put this in your server config
# wordpress rewrite
# unless the request is for a valid file, send to wordpress index
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
full example
server {
listen 80;
server_name site.com;
access_log off;
error_log off;
root /var/www;
index index.php index.html;
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
# wordpress rewrite
# unless the request is for a valid file, send to wordpress index
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Code
html
css
js
scripts