Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

Following the instruction/hint from michaeld at http://www.prestashop.com/forums/topic/18393-solved-move-prestashop-from-subfolder-to-root/

I figured out that it works!

In addition, if you use PrestaShop media servers, please add the rewrite, too.

Here's the complete .htaccess that works for me:

# 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: Make sure that you set Physical URL on PrestaShop BO to "/"

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top