Question

How to redirect local apache ip to domain name

I want to see how to redirect localhost or local IP to a domain name locally… I have a Apache web page hosted locally and I want people in my LAN to access it via something like example.com instead of my IP… Any help??


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @binukpremaratne,

You need to create a redirect in your Apache Configuration file for your IP/default config.

This is not a standart setup so you won’t be able to find the exact tutorial. Having said that, you should be able to cdit the VirtualHost file of your local IP config to something like that:

<VirtualHost 10.0.0.1:80>
    ServerName servername.com
    .....

    RewriteCond %{SERVER_NAME} 10.10.10.1
    RewriteRule /(.*) http://servername.com/$1 [R=301,L]

</VirtualHost>

Alternatively, you can create an .htaccess file in the folder your app is at and have it redirect to a domain name.

Have in mind that most probably redirecting it to a Domain won’t work as you expect as it would require a lot of configuring to make the Domain work for LAN network the way you want.