Jump to:

23355 Posts in 17835 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Subdomains and .htaccess question

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

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

Page: 1
Go to End
Author Topic: 4717 Views
  • jfusco
    Avatar
    Community Member
    52 Posts

    Subdomains and .htaccess question Link to this post

    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

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: Subdomains and .htaccess question Link to this post

    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"

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: Subdomains and .htaccess question Link to this post

    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

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: Subdomains and .htaccess question Link to this post

    hey, now i tested your subdomain again and i see you got it
    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 )

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: Subdomains and .htaccess question Link to this post

    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.

    4717 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.