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.

General Questions /

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

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

HTACCESS issue and 400 error


Go to End
Reply


2 Posts   1397 Views

Avatar
Joefunkx

Community Member, 4 Posts

15 September 2010 at 5:27am

Edited: 15/09/2010 5:28am

Hey guys,
I'm having an .HTACCESS issue that I hope someone can help with. I have done a lot of Google searching but haven't found a solution that worked.

It is a similar issue to this: http://silverstripe.org/archive/show/35627

Anyway, my SS site is in a subfolder on my main hosting path, called sssite in this example.

If I access the site with a slash after the name it works fine: http://www.website.com/sssite/, if I omit the slash then I get the 400 Bad Request error.

Here is my .HTACCESS file:

### 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>

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

If I change the line 5 up from the bottom to: RewriteCond %{REQUEST_URI} ^(.*)/$, then the site will come up fine with no slash, but then when I try to access pages within the site, i.e. http://www.website.com/sssite/page1, I get a "PAGE NOT FOUND" error.

I also played around with modifying the other .HTACCESS file in my root hosting to specifically add a slash when the sssite name is requested, but that didn't work either.

Does anyone have any ideas?

Avatar
Joefunkx

Community Member, 4 Posts

15 September 2010 at 10:38am

Edited: 15/09/2010 10:38am

I solved the issue, and in case anyone else runs into it, here is my updated .HTACCESS file with added code in red:

Note: "sssite" would be replaced with the name of the folder that your site resides in.

### 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>

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