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.

Installing SilverStripe /

Getting SilverStripe up and running on your computer and on your web server.

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

.htaccess mod to remove /ss/ subdirectory from url?


Go to End


10 Posts   9689 Views

Avatar
AlaVive

Community Member, 42 Posts

4 March 2010 at 8:10am

Edited: 04/03/2010 8:10am

Hi, all.

I've installed Silverstripe on a shared host within a "ss" subdirectory. It currently works fine to show the site landing page at www.mysite.com, but all the page appear as "www.mysite.com/ss/page."

If I enter "www.mysite.com/page," it shows fine, but the links don't default to that. I don't know what to change (anywhere) to remove the "ss" from the url.

There are two .htaccess files after installation: one in the root directory:

### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ss

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

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

...and one in the "ss" subdirectory:

# Use PHP5CGI as default
AddHandler fcgid-script .php

### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

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

1) Do I NEED both?
2) Is there a quick solution via .htaccess that doesn't require that I actually MOVE any files? I've searched the forums and the rest of the WWW, but I'm more confused now than when I started.

Thanks!

Avatar
Sean

Forum Moderator, 922 Posts

4 March 2010 at 1:42pm

Edited: 04/03/2010 1:49pm

There's a solution by using virtual hosts, so you can put the site wherever in the web root but still have mysite.com go to it. You might want to read up on this Apache feature, since it's very useful!

e.g.


<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot "/var/www/mysilverstripesite"
</VirtualHost>

You also don't need two .htaccess files. You should only need the one inside your ss directory.

Sean

Avatar
AlaVive

Community Member, 42 Posts

5 March 2010 at 5:42am

Thanks, Sean.

Please forgive me if I'm an utter dork. But, I don't understand.

Isn't this something I have to change in the httpd.conf file? I don't have access to it via the shared hosting account.

If I remove the root (public_html) .htaccess, the site breaks. And, when I modify the .htaccess in the public_html/ss/ directory, it changes nothing.

If it was requiring every address be entered as "www.mysite.com/ss," I think I could wrap my mind around it a bit better. However, the site works correctly by entering "mysite.com" or entering "mysite.com/about."

The problem (for the people I have to please) is that the only way to access the CMS admin is through "mysite.com/ss/admin" (the Security admin will DISPLAY at mysite.com/admin, but it doesn't work) and that, when navigation is selected in the site, the link url is displayed as "mysite.com/ss/about" or "mysite.com/ss/contact."

They want "ss" gone from the url, altogether.

Am I just misunderstanding something?

Thanks again!

Avatar
Sean

Forum Moderator, 922 Posts

7 March 2010 at 7:47pm

I'm not sure who your host is, but when I was on DreamHost they provided me a directory that I could put files in e.g. /home/myusername/mysite.com and then they'd be accessible through mysite.com. Surely there's some mechanism provided by your host to point domains to directories inside your webroot. Have you checked with them?

Avatar
HendriksenRemco

Community Member, 1 Post

30 March 2010 at 9:54pm

Hi there! I also had this problem. But there is a really simple fix for this provided by Silverstripe.
It's the function Director::setBaseURL("http://www.example.com/"). Put that function in your _config.php and your problem should be away.

Avatar
MartinPhone

Community Member, 57 Posts

16 May 2010 at 4:32am

Hello - I have exactly the same problem as the OP - what was your solution? When I try the Director:: line it breaks the CSS. What's the right thing to do?!

Avatar
MitraX

Community Member, 20 Posts

17 November 2011 at 3:05am

Hi there! I also had this problem. But there is a really simple fix for this provided by Silverstripe.
It's the function Director::setBaseURL("http://www.example.com/"). Put that function in your _config.php and your problem should be away.

The problem with this "solution" is that it is not possible to log in to CMS admin. This is very annoying behavior.

Avatar
Lexandclo

Community Member, 55 Posts

19 January 2012 at 4:08am

Hi

Have you tried changing you .htaccess file in the root of your site to
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>

<Files web.config>
Order deny,allow
Deny from all
</Files>

ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html

<IfModule mod_alias.c>
RedirectMatch 403 /silverstripe-cache(/|$)
</IfModule>

<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /

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

if your site is in the root directory leave the rewrite base, if in a sub directory ie yoursite.com/ss
change RewriteBase to RewriteBase/ss

Let me know

Darren

Go to Top