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.

Hosting Requirements /

What you need to consider when choosing a hosting provider and plan.

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

Issues with .htaccess and non www redirects


Reply


2 Posts   1423 Views

Avatar
Mrfixer

Community Member, 49 Posts

3 July 2011 at 1:40am

I have a SS site set up on a server with hostgator no problems at all, however this site will also contain another SS "Add on Domain" which is installed into the public_html folder as addondomain.com, the problem i am having is with the url rewrites from non www to www. this is what i have:

Main domain:

### 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>
DirectoryIndex index.php
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$
RewriteRule (.*) http://www.maindomain.com/$1 [R=301,L]

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

in the add on domain htaccess:

### SILVERSTRIPE START ###
<IfModule mod_dir.c>
DirectorySlash Off
</IfModule>

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^addondomain.com [NC]
RewriteRule ^(.*)$ http://www.addondomain.com/$1 [R=301,NC,L]

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]
### SILVERSTRIPE END ###

as advised the rewrite conditions for non www to www are running below RewriteBase, but what is happening is for both domains the urls from non www do get rewritten but at the end of the url they are suffixed with .com/sapphire/main.php?url=/ this is for both domains, i also tried to force non www through via mysite _config.php but this has the same result.. any ideas? thanks

Avatar
Mrfixer

Community Member, 49 Posts

3 July 2011 at 4:45am

All sorted, originaly when installing the add on domain the main .htaccess file would thorw out a 500 error so i used a different kind of set up htaccess to get around this so i could install, thinking that the error would come back i left it as is, but actually the right thing was to have it with the same .htaccess that is in the add on domain folder... now all is hunky dory!