我最近固定我的網站了一點了PHP MVC魔法,我在我的.htaccess使用這些設置:WAMP本地子域和htaccess的重寫規則
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&arg=$3 [NC,L]
它的工作就像一個魅力。我遇到的唯一問題是,當我參考像css或圖像相對較大的文件時,瀏覽器假定我們移動了文件夾結構,由於URL中的破折號 localhost/projectname/controllername/action/id
so在localhost/controllername/action/id/css/styles.css中請求了css/styles.css。 有絕對路徑解決了這個問題,但在沒有本地測試服務器和遠程實時和開發服務器後沒有很好地工作「projectname」 - 文件夾
我決定配置我的本地wamp服務器,這樣我就可以像我的本地主機一樣訪問我的不同項目,像「http://projectname.localhost」這樣的本地主機。
我激活了相關的Apache模塊,編輯我的hosts文件,並改變了我的httpd-vhosts.conf到
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost.com
ServerAlias www.localhost.com
DocumentRoot "C:\wamp\www"
ErrorLog "logs\errors.log"
<directory "C:\wamp\www">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.com
ServerAlias *.localhost.com
VirtualDocumentRoot "C:\wamp\www\subdomains\%1"
ErrorLog "logs\errors.log"
<directory "C:\wamp\www\subdomains\%1">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
現在,當我打電話projectname.localhost.com/controllername/action/id它告訴我 在此服務器上未找到請求的URL /subdomains/projectname/index.php。 而projectname.localhost.com/index.php仍然爲我提供正確的文件。
我聽說$ _SERVER ['DOCUMENT_ROOT'];可能有問題。這沒有得到妥善設置,但知道這並沒有幫助我解決這個問題呢。
有人可以指點我正確的方向或建議另一個環境配置,使這些情況下的測試成爲可能嗎?