Forum Moderators: phranque
Then I added a second site, as is a local machine I cant make them use domains, or same port, so I use a vhost to serve that site but under port 1006. And all seems to work perfect, but the modrewirte rules in the vhost server, does not work....
this is an example, all calls to:
[localhost...]
are redirected to:
[localhost...]
But if i access the:
[localhost:1006...]
Got a 404 page not found
The root dirs are:
c:/sites/site1 & c:/sites/site2
Both sites has the say.php script and I tested and they work calling directly:
[localhost...]
[localhost:1006...]
Both sites has this .htaccess file:
RewriteEngine on
RewriteRule page/([^/\.]+)/?$ /say.php?page=$1 [L]
And this is the vhost configuration:
Listen *:1006
NameVirtualHost *:1006
<VirtualHost *:1006>
ServerName *
ServerAlias localhost
DocumentRoot "c:/sites/site2"
</VirtualHost>
and just in case, this is the say.php script:
<?php echo $_GET['page']; ?>
So why the modrewrite rules work under localhost:80 and the same file does not work under localhost:1006 ?
Note: running the phpinfo(); command reports that mod_rewrite is eneabled in both servers.
Because port 80 is the de-facto HTTP port, and you are using a non-standard port.
You can indeed use "domains" on your local server, and I suggest that you do so, because forcing the non-standard port in mod_rewrite will make things too complicated when you decide to move the sites to 'real' hosting.
Find your "hosts" file -- That's it, just "hosts' with no file extention, and edit it with a plain-text editor (Windows Notepad will work fine) to add your domain names:
127.0.0.1 example.com
127.0.0.1 example2.com
Now you have sort of a "local DNS server" tht defines these two domains, and requests for those domains will now resolve to your local machine (localhost). Apache can now examine the HTTP Host header sent by the browser to determine which of your two name-based virtual hosts should handle the request.
If for some reason you decide that you must use the port number scheme, then the variable %{SERVER_PORT} will contain the port number of the request currently being processed, and you can test in in a RewriteCond or include it in your substitution URLs.
On WinXP, the hosts file is typically at c:\Windows\system32\drivers\etc\hosts
When you take the sites live with a published domain name in public DNS, simply delete that domain's entry from your hosts file.
Jim
I add to c:\Windows\system32\drivers\etc\hosts:
127.0.0.1 testhost
then I add the vhost definition:
NameVirtualHost *
<VirtualHost *>
ServerName testhost
DocumentRoot "c:/sites/site2"
</VirtualHost>
I restart apache
and the two pages are displayed correctly but accesign
[testhost...]
Gives me again 404 not found
All paths are OK and all files are in place so... why the rules are not appying under the vhost?
AuthUserFile c:/sites/site1/users.txt
AuthName "Please Log In"
AuthType Basic
require valid-user
That pop-up a Login dialog on access, at [localhost...] but it does not in [testhost...]
Is there any diretory option or directive that sould be added to the virtualhost definition to indicate apache that read the .htaccess files?
FYI: the users.txt file contents:
testuser:Ki4cezVjqTTwk
Is there any diretory option or directive that sould be added to the virtualhost definition to indicate apache that read the .htaccess files?
AllowOverride [httpd.apache.org]