3

Currently I'm building application on my local computer. Application is located in /www/projects/mycustomproject/ and for speed of access it has its own personal domain, lets say mycustomproject.com. I have made my Apache-PHP-MySQL available via local network, so anyone can access my project by IP address which is 192.168.1.80 and it's linked to /www/. To access application you have to type 192.168.1.80/projects/mycustomproject/, and here come the problem, by default config for mycustomproject.com is:

RewriteEngine on
RewriteBase /

To access application by IP address it suppose to be:

RewriteEngine on
RewriteBase /projects/mycustomproject/

The question is how can I define rule something like this:

if REMOTE_ADDR == 192.168.*
   RewriteBase /projects/mycustomproject/
else if HOSTNAME == 'mycustomproject.com'
   RewriteBase /
etc.

Possibly there could be other custom conditions based on hostname or IP address and IF/ELSE statements are more preferable over RewriteCond

Nazariy
  • 6,028
  • 5
  • 37
  • 61
  • I guess I don't understand what you're trying to accomplish. Are you trying to make the site accessible via either IP+path or hostname simultaneously? Why? Your problem sounds wrong to me, but a direct solution to it is explained here: http://stackoverflow.com/questions/2045897/with-mod-rewrite-can-i-specify-a-rewritebase-within-a-rewritecond – gregmac Dec 12 '11 at 23:36
  • Sorry if I was not clear anough, I want to make my application to work on local network and on localhost and have different presets (It is accessible over network, no need to worry about router and firewall). Another use of it can be one .htaccess file for local environment and live server. – Nazariy Dec 12 '11 at 23:48

1 Answers1

0

Why don't you just set up mycustomproject as its own virtual host?

Set up a host like:

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

# default root for non-matched ServerName
DocumentRoot /www/

<VirtualHost *:80>
    ServerName local.mycustomproject.com 
    DocumentRoot /www/projects/mycustomproject/
</VirtualHost>

You can then make a local DNS or HOSTS file entry for local.mycustomproject.com.

In this way, you can host as many projects as you want locally (just add more of the <VirtualHost> sections), and they very closely reflect the real production environment.

If you want to use the "real" domain name, just remove the "local." in my example.

You can also use ServerAlias to set up eg, ServerAlias www.local.mycustomproject.com

gregmac
  • 24,276
  • 10
  • 87
  • 118
  • It does have VirtualHost config and it is linked to mycustomproject.com and it is working as expected, the problem is in .htaccess RewriteBase which is configured to work only for domain, and not for IP Address. It suppose to be accessible over network, and should link to different RewriteBase – Nazariy Dec 12 '11 at 23:27