I want to do a redirect in order to give a cleaner url for my users.
I want to change:
http://mydomain.com/main/username/profile
To:
http://mydomain.com/username/profile
Would I do this with a rewrite or an alian and how?
First you have to understand what the difference between a redirect and an alias is.
A redirect will send a user who requests /main/username/profile to /username/profile. The URL will change in the browser. This is particularly important if the URL is accessible by search engines, because they would otherwise index the same page twice (duplicated content).
If you decide to use a redirect you should be sure, that your URLs stay that way. The reason for this is Cool URIs don't change.
Example for a redirect:
server {
# ...
location / {
# ...
location ~ /main/([a-zA-Z0-9]+)/profile$ {
# SEO effective redirect
return 301 /$1/profile;
}
# ...
}
}
An alias is used to tell nginx that that a requested file is not mapped by the URL on the filesystem and that it should have a look elsewhere. The following example is from the nginx wiki:
root /var/www;
location /i/ {
alias /spool/w3/images/;
}
A request for /i/empty.gif will not map to /var/www/i/empty.gif. Instead it will be matched to /spool/w3/images/empty.gif.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With