我有以下.htaccess
文件在我的項目的Web根:Apache2的改寫 - 有條件
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /repos/eamorr.co.uk/react_www/index.html [L,QSA]
上述作品。
當我瀏覽到:
http://localhost/repos/eamorr.co.uk/react_www
我看到我的主頁。
當我瀏覽到:
http://localhost/repos/eamorr.co.uk/react_www/contact-us
我看到「接觸我們」我的主頁的路線(我的網頁上寫的反應)。
好的。大。
現在,一些用戶在Linux上:
當他們籤的代碼,他們看到該網站在一個稍微不同的URL:
http://localhost/_eamorr/develop/eamorr.co.uk/react_www/
和
http://localhost/_eamorr/develop/eamorr.co.uk/react_www/contact-us
關於此行的.htaccess
文件:
RewriteRule . /repos/eamorr.co.uk/react_www/index.html [L,QSA]
取而代之的.
是有一些條件,我可以把從不同的路徑服務的index.html?
例如
RewriteRule {{condition1???}} /repos/eamorr.co.uk/react_www/index.html [L,QSA]
或(不同條件=不同的路徑):
RewriteRule {{condition1???}} /_eamorr/develop/eamorr.co.uk/react_www/index.html [L,QSA]
我怕我的Apache的知識是不是先進的速度迅速做到這一點,我已經花了幾個小時在這!
=================
解決方案:
使用級聯的htaccess重寫規則設置如下:
RewriteEngine On
#RewriteBase/
#Linux localhost:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^.*repos/eamorr.co.uk/react_www.*$
RewriteRule ^([^/]+\.?[^/])*$ /repos/eamorr.co.uk/react_www/index.html [L,QSA]
#Mac localhost:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^.*_eamorr/eamorr.co.uk/react_www.*$
RewriteRule ^([^/]+\.?[^/])*$ /_eamorr/eamorr.co.uk/react_www/index.html [L,QSA]
#develop .co.uk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^.*gitWebFlow/eamorr.co.uk/develop/react_www.*$
RewriteRule ^([^/]+\.?[^/])*$ /gitWebFlow/eamorr.co.uk/develop/react_www/index.html [L,QSA]
#master .co.uk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^.*gitWebFlow/eamorr.co.uk/master/react_www.*$
RewriteRule ^([^/]+\.?[^/])*$ /gitWebFlow/eamorr.co.uk/master/react_www/index.html [L,QSA]
#default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L,QSA]
這足以滿足我現在的需求。
你好,這是一個非常有用的職位。我相應地更新了我的原始問題... – Eamorr
我很高興它很有用,但是您的規則有點失敗,將htaccess移動到似乎是Web根目的地位。這些網站是否在'react_www'上面的目錄中提供任何內容?如果沒有,你應該考慮移動你的'DocumentRoot'或者使用一個符號鏈接,這樣你的repo結構就不必在公共可訪問的文件夾中。重點是它可能可能是你使用相同的(追蹤)文件來管理每個分支。 – Walf