D
D
DeRomanok2012-09-26 13:08:27
Apache HTTP Server
DeRomanok, 2012-09-26 13:08:27

Multi-domain and .htaccess?

Greetings. There is a site written in PHP, the site works with several domains, depending on the domain displays the desired content. In .htaccess, you need to include a set of rules that are used only for a specific domain. Is it possible to include rules from other files in .htaccess, something like:
Include %{HTTP_HOST}.conf?
Maybe there are some other ways?
It’s in my mind to write RewriteCond for each domain, but then .htaccess will be too voluminous.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
S
Sergey, 2012-09-26
@DeRomanok

Only through RewriteCond alas. At least there are fewer problems with it. Do you have VPS/Dedicated or shared hosting?

A
anycolor, 2012-09-27
@anycolor

Are the domains different or subdomains of the same domain?

V
Vladimir, 2012-09-27
@de1vin

On my sites, this is solved at the stage of engine initialization, but the engine is self-written with support for multi-domain architecture. I think this is a more convenient solution than solving it with mod_rewrite

S
sinos, 2012-09-28
@sinos

if your VPS and nginx there, then

S
sinos, 2012-09-28
@sinos

if your VPS and nginx there, then

S
sinos, 2012-09-28
@sinos

server {
listen 80;
server_name domain1.com domain2.com domain3.com;
charset utf-8;
location / {
root /home/www/domains;
index index.php index.html index.htm;
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^/photos/(.*)/(.*)$ /photos/domain1/$1/$2 break;
rewrite ^/photos/(.*)/(.*)$ /photos/domain1/$1/$2 break;
rewrite ^/photos/(.*)/(.*)$ /photos/domain3/$1/$2 break;
rewrite ^/([^/]*)/([^/]*)/$ /index.php?do=$1&type=$2 last;
rewrite ^/([^/]*).html/([^/]*)/$ /index.php?do=$1&page=$2 last;
rewrite ^/([^/]*)/([^/]*).html$ /index.php?do=$1&point=$2 last;
rewrite ^/([^/]*).html$ /index.php?do=$1 last;
rewrite ^/([^/]*)/$ /index.php?do=$1 last;
rewrite ^/sitemap.xml /sitemap.php last;
}
}
location ~ \.php$ {
root /home/www/domains;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/domains$fastcgi_script_name;
include fastcgi_params;
}
}

S
sinos, 2012-09-28
@sinos

and in index.php
$host = $_SERVER['HTTP_HOST'];
$directory = realpath(dirname(__FILE__)).'/config/';
$dir = opendir($directory);
while(($file = readdir($dir))){
if (is_file($directory.$file) && preg_match('/'.$host.'/i', $file)){
include($directory.$ host.".php");
}
}
closedir($dir);
We connect the necessary config depending on the host.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question