Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Subdomains and .htaccess question


Go to End


5 Posts   9085 Views

Avatar
jfusco

Community Member, 53 Posts

4 February 2009 at 3:53am

I am trying to access my silverstripe installation using a subdomain and I'm not having much luck. I know it's an issue with .htaccess but I've been looking at the documentation on the apache site and it's just not clicking.

Here's my setup -
Host: godaddy.com
Main site: http://www.unclebubby.com
Silverstripe install: http://www.unclebubby.com/wavs2 (wavs2 is the subdir where SS is installed)
Desired access: http://wavs.unclebubby.com or http://wav.unclebubby.com

wavs.unclebubby.com currently points to a bunch of redirect pages under a subdir named /wavs. wav.unclebubby.com currently points to the SS install under the /wavs2 subdir.

Current .htaccess file (default):

### SILVERSTRIPE START ###
RewriteEngine On
RewriteBase /wavs2

RewriteCond %{REQUEST_URI} !(^/wavs2$)|(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ 

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
### SILVERSTRIPE END ###

As it is, if I access it directly (www.unclebubby.com/wavs2) it works fine. If I try to access via subdomain (wav.unclebubby.com/wavs2) I get a 404 error which states "The requested URL /wavs2/sapphire/main.php was not found on this server." I worked with someone for a little bit in the chat room last night. They suggested changing the RewriteBase from /wavs2 to mydomain.com/wavs2. I tried several iterations including unclebubby.com/wavs2, www.unclebubby.com/wavs2, /unclebubby.com/wavs2, etc. I didn't try the subdomain with any of those changes because each one I tried broke direct access (www.unclebubby.com/wavs2) with a 500 internal server error.

I've looked at the execution pipeline document (http://doc.silverstripe.org/doku.php?id=execution-pipeline&s=htaccess), which led me to the mod_rewrite documentation (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html), which led me to the URL rewriting guide (http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html). I think I have an elementary grasp of what the .htaccess file is doing but I can't figure out how to get it to do what I -want- it to do, which is allow me to access the site directly or via either subdomain.

I know I'm not the only one who has experienced this but the answers I've found/been given so far have been vague or have not produced the desired results. ANY help is appreciated.

Thanks,
Joe

Avatar
SalvaStripe

Community Member, 89 Posts

4 February 2009 at 4:31am

Edited: 04/02/2009 4:33am

easy easy brother ;)

--> wav.unclebubby.com/wavs2
this is, where your subdomain should go to?

then "wavs2" folder is the root of your subdomain.
you have to change this line in your .htaccess

RewriteBase /wavs2
TO
RewriteBase /

and it should work!

##################
with default .htacess, silverstripe will go to
"wav.unclebubby.com/wavs2/wavs2"
=
"root/wavs2"

Avatar
jfusco

Community Member, 53 Posts

4 February 2009 at 6:10am

Thank you for your reply. That change did get the subdomain working. Unfortunately, it broke direct access. Isn't there a way to look at what URL the person is using and set the baseurl based on that? Like I said, I looked at the documentation but I'm having trouble grasping the specifics of how it works (although I do understand why/how the change you suggested works).

Thanks,
Joe

Avatar
SalvaStripe

Community Member, 89 Posts

5 February 2009 at 9:38pm

hey, now i tested your subdomain again and i see you got it :D
there is no redirection site anymore. and the URL http://wavs.unclebubby.com/ still keeps in adress line while surfing your website!

(i just knew that problem, because i had the same prob just one day before :D)

Avatar
jfusco

Community Member, 53 Posts

7 February 2009 at 5:16am

Just so if anyone else looks at this later, this is what I ended up with for my .htaccess file:

Options +FollowSymLinks

RewriteEngine On

# Change any direct URLs (www.unclebubby.com...) to the subdomain (wavs.unclebubby.com)
RewriteCond %{HTTP_HOST} ^(www\.)?unclebubby\.com$ [NC] 
RewriteCond %{REQUEST_URI} ^/wavs2/(.*)$ [NC] 
RewriteRule .* http://wavs.unclebubby.com/%1 [R=301,L]

# If there is a .htm at the end of the URL, get rid of it (due to migration of site from FrontPage)
RewriteCond %{REQUEST_URI} ^/(.+)\.htm$ [NC] 
RewriteRule ^.+\.htm$ /%1 [R=301,L]

### SILVERSTRIPE START ###

RewriteBase /

RewriteCond %{REQUEST_URI} !^/wavs2$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule !^.+\.(gif|jpg|png|css|js|php)$ ./sapphire/main.php?url=%{REQUEST_URI} [QSA,L]
### SILVERSTRIPE END ###

Everything works beautifully now. Many many thanks to the people over at mod_rewrite forums (http://forum.modrewrite.com) for setting that up for me. They even cleaned up the original code.