2012-11-27 66 views
1

我最近使用prestashop建了一家商店,prestashop的生產安裝位於名爲/ prestashop的服務器的子目錄中。我想要做的是讓你不必去http://mydomain.com/prestashop來查看網站,而只是http://mydomain.com將/ prestashop /部分網址隱藏

有兩種方法我想到目前爲止,我可以移動prestashop的前端控制器索引文件的根,類似於在wordpress中做的,儘管我不確定這是否是一個可行的選擇,因爲我沒有足夠的經驗來解決它。這裏是index.php文件對所有感興趣的那些代碼:

require(dirname(__FILE__).'/config/config.inc.php'); 
Dispatcher::getInstance()->dispatch(); 

第二個選擇是使用Apache的mod_rewrite模塊,使您有類似

RewriteEngine on 
RewriteRule ^/(.*)$ /prestashop/$1 

但我打開htaccess文件已經存在,這代碼是存在的,所以我不知道如果這可以被編輯不能:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ 
RewriteRule . - [E=REWRITEBASE:/prestashop/] 
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L] 

我會繼續玩耍,並試圖找出自己,但你的任何幫助球員將是五個非常感謝。提前致謝。

+0

如果你用'重寫規則重定向^ /(。 *)$/prestashop/$ 1'或任何類似規則,您將無法訪問根目錄。那是你要的嗎? –

+0

是的,我只是希望用戶直接去mydomain.com/prestashop –

回答

1

我不知道是否會的Prestashop正確地計算出路徑,而是試圖改變你的index.php文件:

require(dirname(__FILE__).'/prestashop/config/config.inc.php'); 
Dispatcher::getInstance()->dispatch(); 

我會避免使用的.htaccess這個如果可能的話,因爲它只是更多通過對每個請求進行更多重寫來產生開銷。

基本上所有這些都是修改前端控制器代碼,以便在配置的正確目錄(/ prestashop)中查找。它不應該是一個問題。

編輯:您還需要將.htaccess文件從/prestashop/.htaccess移動到/.htaccess,以便重寫URL仍然有效。

+0

當我這樣做時,它仍然重定向到/ prestashop /,也許這是由於.htaccess文件中的現有代碼? –

+1

它可能是Prestashop中的PHP代碼。有配置文件或管理員定義站點URL的設置嗎?如果是這樣,請嘗試將其更改爲yourdomain.com而不是yourdomain.com/prestashop – drew010

+0

有一個設置有「base uri」,將其更改爲/,現在我的所有css和圖像都已損壞,但無論如何您都可以解決它! :D謝謝你 –

1

http://www.prestashop.com/forums/topic/18393-solved-move-prestashop-from-subfolder-to-root/

指令/從michaeld暗示我想通了,它的作品!

此外,如果您使用PrestaShop媒體服務器,請添加重寫。

下面是完整的.htaccess爲我的作品:

# Copy and paste the following code into the .htaccess file 
# in the public_html folder of your hosting account 
# make the changes to the file according to the instructions. 

# Do not change this line - RewriteEngine on 
RewriteEngine on 

# Change yourdomain.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ 

# Change 'subfolder' to be the folder you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subfolder/ 

# Don't change this line. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Change 'subfolder' to be the folder you will use for your main domain. 
RewriteRule ^(.*)$ /subfolder/$1 

# Change yourdomain.com to be your main domain again. 
# Change 'subfolder' to be the folder you will use for your main domain 
# followed by/then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$ 
RewriteRule ^(/)?$ subfolder/index.php [L] 


# For PrestaShop Media server #1 
# Change mediaserver1.yourdomain.com to be your media server subdomain 
# Change 'subfolder' to be the folder you will use for your main domain. 
RewriteCond %{HTTP_HOST} ^mediaserver1.yourdomain.com$ 
RewriteCond %{REQUEST_URI} !^/subfolder/.*$ 
RewriteRule ^(.*)$ /subfolder/$1 

# For PrestaShop Media server #2 
# Change mediaserver2.yourdomain.com to be your media server subdomain 
# Change 'subfolder' to be the folder you will use for your main domain. 
RewriteCond %{HTTP_HOST} ^mediaserver2.yourdomain.com$ 
RewriteCond %{REQUEST_URI} !^/subfolder/.*$ 
RewriteRule ^(.*)$ /subfolder/$1 


# For PrestaShop Media server #3 
# Change mediaserver3.yourdomain.com to be your media server subdomain 
# Change 'subfolder' to be the folder you will use for your main domain. 
RewriteCond %{HTTP_HOST} ^mediaserver3.yourdomain.com$ 
RewriteCond %{REQUEST_URI} !^/subfolder/.*$ 
RewriteRule ^(.*)$ /subfolder/$1 

PS:請確保您在的Prestashop BO組物理URL爲 「/」