1

Is there a way to rewrite a URL in a local project to look like web page?

For example I have project with url

localhost/site

I'm tryin' to rewirite this to:

www.site.com

or

site.com

That project has subpages, and it would be good if it worked like

site.com/subpage.php

I'm trying for an hour but I'm really htaccess noob.

I work with VertrigoServ and mod_rewrite works fine with some examples which I tried in other projects.

Dariusz Majchrzak
  • 1,227
  • 2
  • 12
  • 22
  • whts the OS where the web server is? – Lucky Chingi Nov 25 '15 at 19:26
  • 1
    Sounds like you may need an entry in your hosts file. See if this helps: [How to setup the hosts file for multiple domains/hosts with the same ip?](http://stackoverflow.com/questions/17505835/how-to-setup-the-hosts-file-for-multiple-domains-hosts-with-the-same-ip) – Grasshopper Nov 25 '15 at 19:45
  • @Grasshopper - that's great, and works exactly as I want. Thanks a lot :) – Dariusz Majchrzak Nov 25 '15 at 19:57

1 Answers1

1

The issue is not with rewrite. To make a local page appear to have a more conventional domain you need to tell your browser that the conventional domain is found on your local webserver.

The simplest way to do this is by editing the hosts file on your OS. On *nix based devices it's usually /etc/hosts, On windows it's usually C:\Windows\System32\drivers\etc\hosts. You will need elevated privileges to edit the file.

Add a line to the end of the file that maps the domain name to your local ip address like this:

127.0.0.1 www.site.com

Close an reopen your browser and visit www.site.com, you should see it is loading the page from your local webserver.

Chances are, you are still seeing the same page as if you view localhost site. To make it load your code you need to change the DocumentRoot in httpd.conf for your apache install to match the directory where your code is.

A preferable solution may be to use Name Based Virtual Hosting, this allows multiple web sites to share the same IP address. Searching 'apache VirtualHost examples' should give you plenty of resources for this. Make sure that NameVirtualHost *:80 is also enabled in order for this to work.

Steve E.
  • 9,003
  • 6
  • 39
  • 57