2013-12-19 155 views
1

我有兩個域當前在我的服務器中,一個用於主域(www.domain.com),另一個用於測試域(test.domain.com)。每個域指向一個包含Joomla安裝的文件夾,並且在每個文件夾中都有安裝隨附的標準.htaccess文件。將重定向子域中的index.php重寫爲.htaccess中的重定向子域

主域名正常工作,但測試域並不像預期的那樣正常工作。如果我瀏覽到test.domain.com,我可以正確地看到主頁,但是如果我瀏覽其他任何地方(即test.domain.com/products.html),則會出現500錯誤。但是,如果我在子域後附加index.php,它按預期工作(即test.domain.com/index.php/products.html)。

這是.htaccess文件/public_html文件夾:

Options +FollowSymLinks 

RewriteEngine On 
RewriteBase/

# pointing www.domain.com to live 
RewriteCond %{HTTP_HOST} !test.domain.com 
ReWriteCond %{HTTP_HOST} www.domain.com 
ReWriteCond %{REQUEST_URI} !^/live/ 
ReWriteRule ^(.*)$ live/$1 [L] 

# pointing test.domain.com to test 
ReWriteCond %{HTTP_HOST} test.domain.com 
ReWriteCond %{REQUEST_URI} !^/test/ 
ReWriteRule ^(.*)$ test/$1 [L] 

# Add a trailing slash to directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.) 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ([^/]+)$ $1/ [L] 

# Rewrite any calls to /* to the index.php file 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ index.php/$1 [L] 

下面是在服務器中的文件夾結構:

/public_html 
    | 
    |--/live    <-- www.domain.com 
    |  | 
    |  |--.htaccess <-- joomla standard .htaccess 
    | 
    |--/test    <-- test.domain.com 
    |  | 
    |  |--.htaccess <-- joomla standard .htaccess 
    | 
    |--.htaccess 

.htaccess文件在livetest文件夾分別有RewriteBase /liveRewriteBase /test

我發現了幾個關於子域重定向的問題,這裏在stackoverflow和許多其他網站,但他們都沒有解決這個具體問題。有誰知道我錯過了什麼?

謝謝。

回答

3

您是否曾嘗試在主域之前放置子域規則? 這裏是我的.htaccess,適用於真正的項目。

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{HTTP_HOST} ^test\.domain.com [NC] 
RewriteRule ^.*$ index-test.php [NC,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^.*$ index.php 
+0

我把子域規則的主要領域之前,但它不起作用。我仍然有同樣的問題。 –

0

我設法解決這個問題部分有關重新排列子域名規則@witzawitz評論,但也通過去除.htaccess文件夾/testRewriteBase /test並在.htaccess文件中的文件夾/liveRewriteBase /live

這是解決方案:

.htaccess文件/public_html文件夾:

Options +FollowSymLinks -MultiViews 

RewriteEngine On 
RewriteBase/

# pointing test.domain.com to test 
ReWriteCond %{HTTP_HOST} test.domain.com 
ReWriteCond %{REQUEST_URI} !^/test/ 
ReWriteRule ^(.*)$ test/$1 [L] 

# pointing www.domain.com to live 
RewriteCond %{HTTP_HOST} !test.domain.com 
ReWriteCond %{HTTP_HOST} www.domain.com 
ReWriteCond %{REQUEST_URI} !^/live/ 
ReWriteRule ^(.*)$ live/$1 [L] 

.htaccess文件中/public_html/live/public_html/test文件夾:

## I have removed license and unnecessary comments 

# Block out any script trying to base64_encode data within the URL. 
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] 
# Block out any script that includes a <script> tag in URL. 
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR] 
# Block out any script trying to set a PHP GLOBALS variable via URL. 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
# Block out any script trying to modify a _REQUEST variable via URL. 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
# Return 403 Forbidden header and show the content of the root homepage 
RewriteRule .* index.php [F] 
# 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 
# 
# If the requested path and file is not /index.php and the request 
# has not already been internally rewritten to the index.php script 
RewriteCond %{REQUEST_URI} !^/index\.php 
# and the request is for something within the component folder, 
# or for the site root, or for an extensionless URL, or the 
# requested URL ends with one of the listed extensions 
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC] 
# and the requested path and file doesn't directly match a physical file 
RewriteCond %{REQUEST_FILENAME} !-f 
# and the requested path and file doesn't directly match a physical folder 
RewriteCond %{REQUEST_FILENAME} !-d 
# internally rewrite the request to the index.php script 
RewriteRule .* index.php [L]