Point 2 domains on the same hosting to different files - apache

I'm having an issue with .htaccess.
I have 3 Domains in one Webspace, all directed to the same content: (www.domain1.com, www.domain2.com, www.domain3.com).
Now I want only the www.domain1.com to start with my WordPress site(index.PHP), the other two domains should start with index.HTM, but I don't want to create subfolders, because all Domains shall have access to the same .htm-Files in the root directory – ONLY the start files (index.php/index.htm) should be different. Is it possible to realize this, for example with mod_rewrite in the htaccess? I tried and failed.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain1.com
RewriteRule ^/$ /index.php [L]
RewriteCond %{HTTP_HOST} ^www.domain2.com
RewriteRule ^/$ /index.htm [L]
RewriteCond %{HTTP_HOST} ^www.domain3.com
RewriteRule ^/$ /index.htm [L]

I managed to find a solution to my problem using PHP instead of .htaccess. It was not the neatest solution but it solves my issue:
switch ($_SERVER ["HTTP_HOST"]) {
case "www.domain1.com":
if ($_SERVER['SCRIPT_URL'] == '/') {
header("Location: http://www.domain1.com/index.php");
} else {
header("Location: {$_SERVER['SCRIPT_URL']}");
}
break;
case "www.domain2.com":
if ($_SERVER['SCRIPT_URL'] == '/') {
header("Location: http://www.domain2.com/index.htm");
} else {
header("Location: {$_SERVER['SCRIPT_URL']}");
}
break;
case "www.domain3.com":
if ($_SERVER['SCRIPT_URL'] == '/') {
header("Location: http://www.domain3.com/index.htm");
} else {
header("Location: {$_SERVER['SCRIPT_URL']}");
}
}

Related

Htaccess to Nginx Rewrite Conversion

htaccess to nginx rewrite conversion help
RewriteEngine On
RewriteCond %{REQUEST_URI} apiv01
RewriteRule ^(.*)$ api.php?params=$1 [NC]
--- edit
I want when access uri GET http://localhost/hospital_project/apiv01/listHospital/3211 can display
{"header":{"code":"401","message":"wrong token"}}
I've used the configuration of anilcetin like this:
location /hospital_project {
if ($uri ~ "apiv01"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*)$ /hospital_project/api.php?params=$1;
}
}
Also i've used the configuration of https://winginx.com/en/htaccess like this:
location / {
rewrite apiv01 /hospital_project/api.php?params=$1;
}
But when i access http://localhost/hospital_project/apiv01/listHospital/3211 the output is equal to http://localhost/hospital_project/apiv01 (no effect)
--- edit
Normal if i using http://localhost/hospital_project/api.php?params=apiv01/listHospital/3211

htaccess Rules convert to NGINX is not working

I want to convert these simple rules in NGINX, i used this website (https://winginx.com/en/htaccess) to convert for me the rules, but somehow, instead of going to the page is downloading the page when i click on it.
Here is the example:
I want to convert these rules to NGINX:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^play/(.*)$ play.php?show=$1 [L]
RewriteRule ^category/(.*)$ category.php?show=$1 [L]
RewriteRule ^contact/(.*)$ contact.php [L]
RewriteRule ^contact$ contact.php [L]
RewriteRule ^terms/(.*)$ terms.php [L]
RewriteRule ^terms$ terms.php [L]
Here is what the website gave me:
# nginx configuration
location /play {
rewrite ^/play/(.*)$ /play.php?show=$1 break;
}
location /category {
rewrite ^/category/(.*)$ /category.php?show=$1 break;
}
location /contact {
rewrite ^/contact/(.*)$ /contact.php break;
}
location = /contact {
rewrite ^(.*)$ /contact.php break;
}
location /terms {
rewrite ^/terms/(.*)$ /terms.php break;
}
location = /terms {
rewrite ^(.*)$ /terms.php break;
}
Someone Can help me?
Thanks a Lot!
You cannot use break here. You should be using last.
The purpose of break is to continue processing within the current location block. In each of the cases above, you require processing to move to the location \.php$ block.
See this document for details.

nginx rewrite rules /about to index.html?page=about

I had some htaccess rules for my server and now I am using nginx instead of apache.
I tried to translate those rules and I came up with:
location /about {
rewrite ^/about\.html$ /index.html?page=about;
}
location /archive {
rewrite ^/archive\.html$ /index.html?page=archiveindex;
}
location /sonic1 {
rewrite ^/sonic1/index\.html$ /index.html?page=archivegame&game=s1;
}
location /sonic2 {
rewrite ^/sonic2/index\.html$ /index.html?page=archivegame&game=s2;
}
location /sonic3 {
rewrite ^/sonic3/index\.html$ /index.html?page=archivegame&game=s3;
}
For some reason these rules do not work
Long story short when someone acceses my website and writes:
/about or /about.html i want it to be redirected to this page /index.html?page=about
These applies to all the other rules, if the about one will work I will figure out how to do the rest of them.
Any help would be really appreciated!
Original apache rules:
RewriteRule ^about\.html$ index.html?page=about
RewriteRule ^archive\.html$ index.html?page=archiveindex
RewriteRule ^sonic1/index\.html$ index.html?page=archivegame&game=s1
RewriteRule ^sonic2/index\.html$ index.html?page=archivegame&game=s2
RewriteRule ^sonic3/index\.html$ index.html?page=archivegame&game=s3
RewriteRule ^sonicandknuckles/index\.html$ index.html?page=archivegame&game=sk
As promised, I am publishing the nginx rules that I came up in the end for my previous apache rules (htaccess).
location = /about {
rewrite ^/about$ /index.html?page=about permanent;
}
location = /archive {
rewrite ^/archive$ /index.html?page=archiveindex permanent;
}
location = /sonic1 {
rewrite ^/sonic1$ /index.html?page=archivegame&game=s1 permanent;
}
location = /sonic2 {
rewrite ^/sonic2$ /index.html?page=archivegame&game=s2 permanent;
}
location = /sonic3 {
rewrite ^/sonic3$ /index.html?page=archivegame&game=s3 permanent;
}
location = /sonicandknuckles {
rewrite ^/sonicandknuckles$ /index.html?page=archivegame&game=sk permanent;
}

Apache .htaccess rule to Nginx

Please help me convert the following Apache htaccess rules to Nginx
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://192.168.201.112/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.201.112$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|swf)$ - [F,NC]
Thanks in advance
This configuration means only 192.168.201.112 can access the resouce which has extsion name (jpg|jpeg|gif|png|bmp|swf) in this server. You can use the following nginx config:
location ~ .*\.(jpg|jpeg|gif|png|bmp|swf)$ {
set $hit false;
if ($http_referer ~ "^http://test1.test.com/.*$"){
set $hit true;
}
if ($http_referer ~ "^http://test1.test.com$"){
set $hit true;
}
if ($hit = false) {
return 403;
}
}

rewrite rule for codeigniter

this is my controller in CI
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
}
function bil($model='')
{ }
I want to do a rewrite so that
http://example.com/index.php/welcome/bil/model
becomes
http://example.com/model
in my htaccess I have
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/welcome/$1 [L]
#RewriteRule ^(.*)$ /index.php/welcome/bil/$1 [L]
I thought it should be as easy as removing the /index.php/welcome/ part
but when I uncomment the last line it get 500 internal server error
You'll want to use mod_rewrite to remove your index.php file like you have above, but use CodeIgniter's routing features to reroute example.com/model to example.com/welcome/bil/model.
In your routes.php configuration file, you can then define a new route like this:
// a URL with anything after example.com
// will get remapped to the "welcome" class and the "bil" function,
// passing the match as a variable
$route['(:any)'] = "welcome/bil/$1";
So then, typing example.com/abc123 would be equivalent to example.com/welcome/bil/abc123.
Note that only characters permitted by $config['permitted_uri_chars'] (which is located in your config.php file) are allowed in a URL.
Hope that helps!