Question

I have developed a PHP webshop project which works independently for each customer. Meaning each customer installs own webshop source files, php.

I found out that this is a killer to maintain many websites so I decided to place the source files of the webshop in a common place in the server and create an alias on the apache server so all www customers have access to it.

Then each customer has own config file, log folder, template folder etc. in their own www folders.

I managed to do all of the stuff above. But my problem is the URL.

URLs will look as follows: http://www.exampleshop.com/webshop/v1/index.php

I need to hide the webshop/v1 in the url so it looks as follows: http://www.exampleshop.com/index.php

I played with url rewrite mod but it keeps telling that the index.php does not exist as it does look for the file in the root of exampleshop.com which is not correct, it is in /webshop/v1

Any ideas? alternatives.

Hope someone can help :-)


I managed to do the above with the followings :-)

RewriteEngine On
#for admin pages redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$/admin/index\.php$ /webshop/v1/admin/$1 [L]

#for webshop pages redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /webshop/v1/$1 [L]

the aboves works, but the only problem is that it does not recognize the index file. when I go to url without specifying a page it doesn't work as index file wont work. I have to type full url such as webshop.com/index.php to get it to work.

and is there a way to remove the extension too :-)

Solutions which works also without specifying index.php in url

#if no file specified, forward to index
RewriteRule ^$   webshop/v1/   [L]
#if no file specified, forward to index
RewriteRule ^admin/$   webshop/v1/admin/   [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /webshop/v1/$1 [L]
Était-ce utile?

La solution

I'd route the requests a application-level based on the host.

Say you have the files installed on your server, and various domains pointing at this server, i.e. customer1.com, customer2.com, customer3.com etc. Then, in your index.php file, just detect which domain the files are being accessed from and switch configuration settings as required.

You could have a database table that maps settings to domains, so you can do a database query and fetch settings if you didn't want to use file-based configuration.

UPDATE

Well, in that case, you want a .htaccess rule. Please this in your root .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$   webshop/v1/   [L]
    RewriteRule (.*) webshop/v1/$1 [L]
</IfModule>

And this in your /webshop/v1/ directory:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # for admin pages redirection
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^admin/(.*)$ /webshop/v1/admin/$1 [L]

    # for webshop pages redirection
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /webshop/v1/$1 [L]
</IfModule>

Autres conseils

VirtualHost or Alias directives should fix it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top