• example.com
  • sub.example.com

When I access example.com/sub, I want to redirect sub.example.com, while browser address still remains example.com/sub

Is it possible?

closed as off-topic by womble Oct 17 at 8:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


Then you'll probably want to insert a virtualhost in your nginx configuration. Something like:

server {
    listen 80;
    server_name sub.example.com;
    rewrite ^(.*)$ $scheme://example.com/sub/$1 redirect;
  • It doesn't work...(maybe due to another configs..) Can I link example.com/sub with sub.example.com's index file then? – user544940 Oct 17 at 8:29
  • You may want to make sure that sub.example.com isn't listed as a server_name in any other vhost. Setting up a link: not sure. Please update your question: what OS, content for nginx.conf and "relevant included configs" (mostly your vhosts, not sure what you've customized on your own, ...). Some logs might help as well (/var/log/nginx) – SYN Oct 17 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.