Making the /prestashop/ part of the url invisible

Carwyn Stephen picture Carwyn Stephen · Nov 27, 2012 · Viewed 8k times · Source

I've recently built a shop using prestashop and the production install of prestashop is in a subdirectory on the server called /prestashop. What I want to do is make it so that you don't have to go to http://mydomain.com/prestashop to view the website but rather just http://mydomain.com

There are two ways I've thought of so far, I could move prestashop's front controller in the index file to the root, similar to what is done in wordpress, although I'm not sure if this is a viable option as I'm not experienced enough to mess around with it. Here's the code of index.php for all those interested:

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

The second option is to use apache's mod_rewrite module so you have something like

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

But I open the htaccess file already there and this code is there, so I don't know if this can be edited or not:

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

I'll keep on playing around and trying to figure it out myself, but any help from you guys would be very greatly appreciated. Thanks in advance.

Answer

drew010 picture drew010 · Nov 27, 2012

I'm not sure if Prestashop will figure out the paths correctly, but try changing your index.php file to:

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

I'd avoid using .htaccess for this if possible since its just more overhead to incur by doing more rewrites on each request.

Basically all this does is modify the front controller code to look in the correct directory (/prestashop) for the configuration. It shouldn't be a problem for it.

EDIT: You'll also need to move the .htaccess file from /prestashop/.htaccess to /.htaccess so the rewrites for URLs still work.