Search code examples
.htaccesshttp-redirectdnssubdomain

htaccess based redirect subdomain to folder in main domain


I have problem with my htaccess file.

My main domain kielkowski-szkolka.pl points to root folder /kielkowski-szkolka.pl/public_html Now, I created subdomain automatyka.kielkowski-szkolka.pl with points to /kielkowski-szkolka.pl/public_html/automatyka

Now when I try to go to automatyka.kielkowski-szkolka.pl it redirects me to / of my main domain, kielkowski-szkolka.pl

Can you look my root htaccess and tell me what to add/change to make it work?

SetEnv PHP_VER 5
php_flag apc.enabled On
php_flag apc.cache_by_default On
php_value session.gc_maxlifetime 86400
php_value session.cookie_lifetime 86400
Options +FollowSymLinks
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

#przekierowanie z http na https i z ww na bez www
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^kielkowski-szkolka.pl [NC]
RewriteRule ^(.*)$ https://kielkowski-szkolka.pl%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://kielkowski-szkolka.pl/$1 [R=301,L]
# Redirect non-existing files or folders to index
# Redirect non-existing files or folders to index
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ / [L,QSA,R=301]
</IfModule>

Solution

  • You can check for your subdomain and then redirect to the folder like this for example.

    RewriteCond %{HTTP_HOST} ^automatyka\.kielkowski-szkolka\.pl$
    RewriteRule ^(.*)$ http://kielkowski-szkolka.pl/automatyka/$1 [L,R=301]