2015-06-11 23 views
0

我有一個OpenCart多層安裝,這就是爲什麼我有幾個域指向同一個服務器文件夾。在這個文件夾中,我有一個.htaccess文件,我只能使用其中一個域(在這種情況下:city-gardener.com)。在一個域中使用一個.htaccess文件

下面是代碼:

# Prevent Directoy listing 
Options -Indexes 

# Prevent Direct Access to files 
<FilesMatch "\.(tpl|ini|log)"> 
Order deny,allow 
Deny from all 
</FilesMatch> 

RewriteEngine On 
RewriteBase/

# append WWW 
RewriteCond %{HTTP_HOST} !^www. 
RewriteCond %{HTTP_HOST} !^$ [NC] 
RewriteRule ^(.*) https://www.%{HTTP_HOST}/$1 [R,L=301] 

# delete trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} (.*)$ 
RewriteRule ^(.+)/$ https://www.city-gardener.com/$1 [R,L=301] 

# Force SSL 
RewriteCond %{HTTPS} !=on 
RewriteRule ^(.*)$ https://www.city-gardener.com/$1 [R,L=301] 
RewriteCond %{HTTPS} !=off 

# SEO URL Settings 
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] 
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) 
#RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 
RewriteRule ^(?:(?:(\w{2})(?:/|\z))?(?:/|\z)?)?(?:([^?]*))? index.php?_route_=$2&site_language=$1 [L,QSA] 

我會如何改變這種做法,它適用於其他領域一樣的?我知道我需要用{HTTP_HOST}之類的東西替換硬編碼的域名,但我總是會在我的網址或類似錯誤中出現幾個www.。如果有人能幫忙,會很棒!

+0

什麼是這一點,不工作的示例網址? – anubhava

+0

一個域名是city-gardener.com域名,另一個域名是.de域名(diestadtgaertner.de) –

回答

0

您設置了錯誤的標誌:[R,L=301]而不是[R=301,L],您的網址被重寫了多次,並且您添加了幾個www

爲了擺脫明確指定域名,修改規則,這樣

# delete trailing slash 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ /$1 [R=301,L] 

# Force SSL 
RewriteCond %{HTTPS} !=on 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 
+0

嗨,非常感謝您的回答。它仍然不適用於那個。問題是,我不知道如何調整htaccess以擺脫當前包含的域名。 –

+0

我編輯了答案 – umka

+0

嗨,非常好,非常感謝你。這很好用! –

相關問題