Hi,
I'm trying to test redirects and I've been going through the rewrite documentation but not able to wrap my head around it. I wanted to redirect this URL: https://classbproject.com/contact to this URL: https://classbproject.com/category/guides/. I wrapped my rewrite within a location block but that does not work. What am I missing?
My server config is as shown below:
server {
## Your website name goes here.
server_name classbproject.com;
## Your only path reference.
root /var/www/classbproject;
## This should be in your http block and if it is, it's not needed here.
index index.php index.html index.htm;
error_log /var/log/classbproject_error_log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location /contact/ {
rewrite \/contact\/ \/category\/guides\/ last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1d;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/classbproject.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/classbproject.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = classbproject.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name classbproject.com;
## Your only path reference.
root /var/www/classbproject;
listen 80;
return 404; # managed by Certbot
}
I'm trying to test redirects and I've been going through the rewrite documentation but not able to wrap my head around it. I wanted to redirect this URL: https://classbproject.com/contact to this URL: https://classbproject.com/category/guides/. I wrapped my rewrite within a location block but that does not work. What am I missing?
My server config is as shown below:
server {
## Your website name goes here.
server_name classbproject.com;
## Your only path reference.
root /var/www/classbproject;
## This should be in your http block and if it is, it's not needed here.
index index.php index.html index.htm;
error_log /var/log/classbproject_error_log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location /contact/ {
rewrite \/contact\/ \/category\/guides\/ last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1d;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/classbproject.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/classbproject.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = classbproject.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name classbproject.com;
## Your only path reference.
root /var/www/classbproject;
listen 80;
return 404; # managed by Certbot
}