3

Ok So i have come across a problem with my htaccess and how to get it to work.

I have just purchased a ssl wildcard for my primary and sub domains. I am with bluehost and they suggest adding this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

At the moment all i have is this...

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]

RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

and that works however, i cannot get it so that when i open the file, it just opens the file with no redirects... So If i open sub.domain.com/file/fil1.js it will open the index.php which is what i do not want...

but if i do /browse or something like that it works...

Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
Kevin Upton
  • 3,336
  • 2
  • 21
  • 24

2 Answers2

1

Ok after much mucking around and playing around it was the file request which wasnt including the subdomain folder, which was causing it to not find the file location. So I managed to do a manual check for the file, and this is what i got. This seems to do exactly what i want. Im not sure if there is a more efficient way, but this is what it got.

#-------------------SUB.DOMAIN.COM---------------------
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} -f
RewriteRule . %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule . sub_folder/index.php [L]
#--------------------------------------------------------------

instead of

RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
Kevin Upton
  • 3,336
  • 2
  • 21
  • 24
0

You need to change your second rule so that it only gets applied when the request is ^(/)?$, then you need to duplicate what bluehost tells you to do. Essentially, replace:

RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]

With what they tell you to use:

RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1 [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^/?$ /sub_folder/index.php [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Ok so i did that. And what is happening is that it will load the sub_folder/index.php on the sub.domain.com url,, however if i was to say type sub.domain.com/file/location.php to an exact file, it loads my main site's index.php file. and what i want it to do is just open sub_folder/file/location.php as it would normally on a subdomain... – Kevin Upton Nov 24 '12 at 14:57
  • @KevinUpton I left out a `[L]` but the `/index.php` in your main site only gets loaded if `sub_folder/file/location.php` doesn't exist (or whatever you end up requesting doesn't exist). The `RewriteCond %{REQUEST_FILENAME} !-f` condition ensures that. – Jon Lin Nov 24 '12 at 15:17
  • Yer exactly i think that is the bit that is causing it to not work :/ haha – Kevin Upton Nov 24 '12 at 20:05
  • and when i remove the last bit which is redirecting it to the index, to test if it actually gets the file, it comes up with an error... – Kevin Upton Nov 25 '12 at 01:00