How to point a subdomain to a subfolder - laravel

I have an Apache server running ISPConfig. On a domain example.com I am pointing its subdomains to subfolders, e.g. foo.example.com to /sub/foo. This works fine:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]
Now I need to point one specific subdomain into a subfolder's subfolder (bar.example.com into /sub/bar/public to use Laravel). But for some reason, this does not work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^bar\.example\.com/
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]

The problem was the / at the end of the domain name. If I delete it or put there $, it works.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^bar\.example\.com$
RewriteRule ^/(.*)$ /sub/bar/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/example\.com/
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^/(.*)$ /sub/%1/$1 [L]

Related

Having difficulty OHS rewrite rule for multiple domains

I'm having a bit of difficulty with rewriting on Oracle HTTP Server for multiple domains that point to same IP address and port
Following is working
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
However when I try https://sub-doamin-2/analytic it redirects to the https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL
Tried RewriteCond ${HTTP_HOST} method with no luck. It just redirect to / (root)
RewriteEngine On
RewriteCond ${HTTP_HOST} sub-doamin-1$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-1/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
RewriteCond ${HTTP_HOST} sub-doamin-2$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub-doamin-2/analytics
Can you please assists resolving this issue?
It should be %{HTTP_HOST} instead of ${HTTP_HOST}
So the rules should be:
RewriteCond %{HTTP_HOST} sub1.test.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub1.test.com/psp/UACMP/SELF_SERVICE/SA/c/NUI_FRAMEWORK.PT_LANDINGPAGE.GBL [R,L]
RewriteCond %{HTTP_HOST} sub2.test.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ https://sub2.test.com/analytics [L]
You can check the rules here: https://htaccess.madewithlove.be?share=6632e45c-a7bb-5099-ab0b-468ba1066277
for the urls https://sub1.test.com and https://sub2.test.com
If you write your original rules in that website you will get This test string is not supported: ${HTTP_HOST} so this can also help you next time.

Laravel .htaccess with forced HTTPS

I use this .htaccess file in root directory of my Laravel website on hosting, so the visitors dont see /public/ in URL address:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my-domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.my-domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
But so far I couldnt find a simple solution to add forced HTTPS redirection. Any suggestions please?
Force domain to use https using .htaccess
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
modify your .htaccess with this code:
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
This will help you
You should try below in .htaccess
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.my-domain.com/$1 [R=301,L]

Virtual domains and subdomains using mod_rewrite

I would like to create a service where a user either can get a subdomain or a regular domain on my service.
The idea is that all subdomains except www. should go to /subdomains.php?user=[sub]&url=[requestet url]
And all domains except my own 2 domains should go to /domain.php?url=$1
My 2 domains are:
domain1.com and domain2.se
I've tried the following code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain2\.se$ [NC]
RewriteRule ^(.*)$ /subdomain.php?user=%2&url=$1 [QSA,L]
#Rewrite
RewriteCond %{HTTP_HOST} !^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain2\.se$ [NC]
RewriteRule (.*) http://www.domain1.com/domain.php?url=$1 [R=301,L]
</IfModule>
But it does not seen to work.
Sub domains: how do you expect an URL to be both a subdomain of domain1.com and domain2.se at the same time?
Try e.g. this simplification:
RewriteCond %{HTTP_HOST} !^www\.(domain1\.com|domain2\.se)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.(domain1\.com|domain2\.se)$ [NC]

REQUEST_URI must NOT end on

how can I do this?
RewriteCond %{REQUEST_URI} !payment\.callback\.php$ [NC]
the uri must not end on payment.callback.php
EDIT:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(secure)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !payment\.[^.]\.php$ [NC]
RewriteRule ^(.*)$ https://%1.domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(demo|secure)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.com/_secure/ [NC]
RewriteRule ^(.*)$ /_domain.com/_secure/$1 [L]
I don't want to rewrite (http => https) urls to secure.domain.com that ends on payment\.[^.]+\.php$

how to set language

how can I set the language (en, da, de etc) with mod_rewrite?
all files are located in the same dir
url to set language is
?set_lang=da
rewrite:
www.domain.com/en/index.php => www.domain.com/index.php?set_lang=en
www.domain.com/en/another_page.php?cat=black => www.domain.com/another_page.php?set_lang=en&cat=black
www.domain.com/da/index.php => www.domain.com/index.php?set_lang=da
www.domain.com/da/another_page.php?cat=black => www.domain.com/another_page.php?set_lang=da&cat=black
EDIT:
my .htaccess looks like this
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/ [NC]
RewriteRule ^(.*)$ /_domain.net/$1 [L]
RewriteCond %{HTTP_HOST} ^(demo|mysql|secure)\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/_(demo|mysql|secure)/ [NC]
RewriteRule ^(.*)$ /_domain.net/_%1/$1 [L]
RewriteCond %{HTTP_HOST} domain\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/_domain\.net/ [NC]
RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
I found a solution
RewriteCond %{HTTP_HOST} domain\.net$ [NC]
RewriteCond %{REQUEST_URI} ^/(da|en)/(.*)(\?%{QUERY_STRING})?$ [NC]
RewriteRule ^(.*)$ /%2?%{QUERY_STRING}&set_lang=%1 [L]

Resources