使/ prestashop / url的一部分不可见

时间:2012-11-27 22:49:07

标签: php .htaccess prestashop front-controller

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

到目前为止我有两种方法可以考虑,我可以将prestashop的前端控制器在索引文件中移动到root,类似于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]

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

2 个答案:

答案 0 :(得分:1)

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

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

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

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

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

答案 1 :(得分:1)

遵照迈克尔德在http://www.prestashop.com/forums/topic/18393-solved-move-prestashop-from-subfolder-to-root/

的指示/提示

我发现它有效!

此外,如果您使用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设置为“/”