问题
I'm using wamp on localhost at c:\wamp\www\
.
The project located under: c:\wamp\www\MyProj\public
(root).
In file1.php
(located in root) I have a link to some fake url (/services/.....).
I'm trying to redirect that url to other file service_router.php
(in the same direction as file1.php).
I'm doing that in httpd.config:
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot c:\wamp\www\
<Directory "c:\wamp\www\">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/MyProj/public/services/*
RewriteRule . /MyProj/public/service_router.php
</VirtualHost>
But my WAMP refuses to restart.
What's wrong with my configurations?
回答1:
Can I make a few suggestions.
If you want to use Virtual Hosts, and I consider that a very good idea. You need first to make sure that localhost still works and secondly it is a good idea to move you actual projects out of the \wamp\
folder structure.
So this would be a good starting point for your first ( of many ) VHOSTS
First create a new folder structure somewhere on any of your drives for example
C:\websites\project1\www
Now copy your project to the www folder.
Now setup the vhosts
# must be first VHOST so the that localhost and the wamp menu page still work
# Also makes this the default site so any randon hacks on your ip address
# will come here and hopefully be rejected because it only 'Allows' access
# from this machine ( see Allow Deny )
<VirtualHost *:80>
DocumentRoot "D:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/websites/project1/www"
ServerName project1.dev
ServerAlias www.dqsc.old
Options Indexes FollowSymLinks Includes ExecCGI
<Directory "C:/websites/project1/www">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Unless you actually want to make this site available to the World can I suggest that you dont use Allow from all
.
Try using or the second Allow line if you want to see your site from any machine on your internal network, just use the first 3 of the 4 quartiles of your ip address and it will allow access from any ip starting with those 3 quartiles.
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 localhost ::1
Allow from 192.168.0
Now you need to amend your HOSTS
file so that windows knows about your new domain name.
Edit c:\windows\system32\drivers\etc\hosts
and add the new site name project1.dev
like so, you will have to launch your editor 'Run as Administrator' as this file is protected by windows :-
127.0.0.1 project1.dev
Now restart the "DNS Client" service to refresh the windows dns cache so it see's your new domain name. Start a command window, again "Run as Administrator".
net stop "DNS Client"
net start "DNS Client"
You should now be able to enter http://project1.dev
in a browser and it will find you new site.
Finally, once you test that your site is working, put the url rewrite coding in a .htaccess
file in the root of your new project.
C:\websites\www\project1\.htaccess
来源:https://stackoverflow.com/questions/22666482/wamp-httpd-config-redirect