2012-01-28 31 views
0

我正在使用一個飛機網站並使用.htaccess文件來重寫URLS以使它們更友好。下面是該文件:.htaccess Mac OSX服務器的重寫規則問題,在Unix服務器上不存在

AddType application/x-httpd-php /(.*) 
Options +FollowSymLinks 
RewriteEngine on 
RewriteRule ^general-aviation-models/(.*)/(.*) /models.php?mfg=$1&model=$2 
RewriteRule ^general-aviation/(.*)/(.*) /general.php?page=$1&sub=$2 
RewriteRule ^general-aviation/(.*) /general.php?page=$1 
RewriteRule ^general-aviation /index.php 
RewriteRule ^military/(.*) /military.php?page=$1 
RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2 
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1 
RewriteRule ^cart/ /cart.php 
RewriteRule ^contact/ /contact.php 
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2 
RewriteRule ^commercial/(.*) /commercial.php?page=$1 
RewriteRule ^commercial/ /commercial.php 
RewriteRule ^links/ /links.php 
RewriteRule ^about/ /about.php 
RewriteRule ^tour/(.*) /tour.php?page=$1 
RewriteRule ^tour/ /tour.php 

ExpiresDefault "access plus 10 years" 
AddOutputFilterByType DEFLATE text/plain 

這在我的本地開發環境基於* NIX的服務器上的工作以及對甲基苯丙胺,但在遷移到Mac OSX服務器,幾個(但不是全部)規則失敗。特別是,這些失敗:

RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2 
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1 
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2 
RewriteRule ^commercial/(.*) /commercial.php?page=$1 

其他說明:

  • mod_rewrite的模塊成功加載(在加載的模塊顯示出來的phpinfo節())
  • 我有AllowOverride全部在我的httpd.conf文件(在適當的標籤中)
  • 我的服務器API是Apache 2.0的處理程序

我環顧四周,等了一段時間,但並沒有太大找到。我嘗試的第一個解決方案this SO question但添加的行導致此錯誤在我的日誌:

/my_specific/document_root/.htaccess: DocumentRoot not allowed here 

有什麼建議?

UPDATE:

原來Apache的在Multiviews功能已上結束了我的大多數的RewriteRules的工作,無論如何,但覆蓋他們,並導致上市4級的故障。我所要做的就是加入到我的htaccess文件的頂部:

Options -MultiViews 

回答

4

原來Apache的在Multiviews功能是默認情況下它結束了我的大多數的RewriteRules的工作反正打開,但被重寫他們並引起列出的4個故障。我所要做的只是將其添加到我的htaccess文件的頂部:

Options -MultiViews 
0

下面我將如何改變你的RewriteRules:

AddType application/x-httpd-php /(.*) 
Options +FollowSymLinks 
RewriteEngine On 

RewriteRule ^/?$ /index.php [NC,QSA,L] 
RewriteRule ^(tour|cart|links|about|military(-models)?|general-aviation|commercial|contact)/?$ /$1.php [NC,QSA,L] 

RewriteRule ^general-aviation-models/([^/]+)/(.*) /models.php?mfg=$1&model=$2 [NC,QSA,L] 
RewriteRule ^general-aviation-models/(.+) /models.php?mfg=$1 [NC,QSA,L] 

RewriteRule ^general-aviation/([^/]+)/(.*) /general.php?page=$1&sub=$2 [NC,QSA,L] 
RewriteRule ^general-aviation/(.+) /general.php?page=$1 [NC,QSA,L] 

RewriteRule ^military-models/([^/]+)/(.*) /military-models.php?mfg=$1&model=$2 [NC,QSA,L] 
RewriteRule ^military-models/(.+) /military-models.php?mfg=$1 [NC,QSA,L] 

RewriteRule ^commercial/([^/]+)/([^/]+) /commercial.php?page=$1&sub=$2 [NC,QSA,L] 
RewriteRule ^commercial/(.+) /commercial.php?page=$1 [NC,QSA,L] 

RewriteRule ^military/([^/]+) /military.php?page=$1 [NC,QSA,L] 
RewriteRule ^tour/(.+) /tour.php?page=$1 [NC,QSA,L] 

ExpiresDefault "access plus 10 years" 
AddOutputFilterByType DEFLATE text/plain 

通過我很抱歉地說,方式,但你的設計還有改進的空間。

一般人重定向所有index.php然後解碼在PHP代碼URL

想想吧;)

+0

感謝您的回答!不幸的是,OSX服務器仍然存在上述部分的問題。通過「解碼在PHP代碼中的URL,你的意思是解析它,並指示使用PHP的請求?我可以看到這將消除我的問題。你能指引我到一個SO文章或某處我可以看到一個這樣的例子嗎? ! – AndyPerlitch 2012-01-28 23:54:41

+0

因爲我遵循你的Rewrite規則,所以我並不是想把'contact'改成'index',只是我之後的評論可能讓你覺得:) – 2012-01-29 10:32:32

+0

哎呀。非常感謝你的幫助。我在Front Controller模式上發現了很多東西,我認爲這很好。 – AndyPerlitch 2012-01-29 21:43:54