1

我最近使用 prestashop 建立了一个商店,prestashop 的生产安装位于服务器上名为 /prestashop 的子目录中。我想做的是让你不必去http://mydomain.com/prestashop来查看网站,而只需http://mydomain.com

到目前为止我想到了两种方法,我可以将 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]

我会继续玩,并试图自己弄清楚,但你们的任何帮助将不胜感激。提前致谢。

4

2 回答 2

1

我不确定 Prestashop 是否会正确计算路径,但请尝试将 index.php 文件更改为:

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

如果可能的话,我会避免使用 .htaccess ,因为通过对每个请求进行更多的重写会产生更多的开销。

基本上所有这些都是修改前端控制器代码以在正确的目录(/prestashop)中查找配置。它不应该是一个问题。

编辑:您还需要将 .htaccess 文件从 /prestashop/.htaccess 移动到 /.htaccess 以便 URL 的重写仍然有效。

于 2012-11-27T22:54:52.253 回答
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 设置为“/”

于 2012-11-30T04:40:31.353 回答