Search

If I remember correctly, earlier version of Symphony automatically redirected a site either to the main domain or the www subdomain based on the configuration settings. I’m not sure if this was a 1.7 or 2.0 beta feature but — nevertheless — Symphony’s behaviour changed a while back.

Does anyone know how to change the main .htaccess file of Symphony 2.0.8 to automatically redirect all request to only one of the two domains?

Force www

RewriteCond %{HTTP_HOST} ^symphony-cms\.com$ [NC]
RewriteRule ^(.*) http://www.getsymphony.com%{REQUEST_URI} [R=301,L]

Remove www

RewriteCond %{HTTP_HOST} ^www\.symphony-cms\.com$ [NC]
RewriteRule ^(.*) http://getsymphony.com%{REQUEST_URI} [R=301,L]

Either one of them has to go right after RewriteEngine On.

This is what no-www.org suggests:

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

Oh, what a beautiful solution! I never got deep enough into Apaches environment variables to find a solution that doesn’t require hardcoded domain names. Great find!

Thanks, Nils. Works like a charm!

Ah, Marco, that’s even better!

By the way, it doesn’t seem to make any difference if I put the rule before or after

 RewriteBase /

By the way, it doesn’t seem to make any difference if I put the rule before or after RewriteBase /

Correct. Although it might make a difference if the value is something else than just /. From a gut-feeling I think it should go before it.

I just wanted to make sure you put it before all the other RewriteCond or RewriteRule directives.

Cool :D

I default to non-www now just because I like the shorter URLs but is there any actual benefit to doing this? Aside from the obvious not having to write “www.” all the time?

Google might penalise for having duplicate content if you serve the same content on both places.

(and even if it doesn’t, it will still see them as different urls, so incoming links won’t count for the same url, if that makes sense)

this doesnt work (hardcoded or variables) when used together with the language redirect extension, its event redirects the site to a specific(browser language) param upon load, and adds this in the htaccess file to clean that up;

### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de)-?()?/(.*/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end

so there is no ‘root’ state and the abve doesnt have any effect. Any clues as to how to combine?

Any clues as to how to combine?

I’d still say before all the other RewriteConds or RewriteRules. Can you show us your complete .htaccess?

sure;

### Symphony 2.0.x ###
<IfModule mod_rewrite.c>

RewriteEngine on

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

### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico"
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC]
RewriteRule .* - [S=14] 

### IMAGE RULES 
RewriteRule ^image/(.+.(jpg|gif|jpeg|png|bmp))$ ./extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC]

### ADMIN REWRITE
RewriteRule ^symphony/?$ ./index.php?mode=administration&%{QUERY_STRING} [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^symphony(/(.*/?))?$ ./index.php?symphony-page=$1&mode=administration&%{QUERY_STRING} [NC,L]

### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|nl)-?()?/(.*/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end

### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/?)$ ./index.php?symphony-page=$1&%{QUERY_STRING}  [L]

</IfModule>
######

btw the master of the default workspace uses a png bookmark, not a favicon ico….

shouldnt the rewrite base be different seeing the countrycode redirects…?

I would expect your .htaccess to work as expected. You can set the RewriteLog and RewriteLogLevel directives appropriately and have a look at the logs (or post them here if you don’t understand them).

btw the master of the default workspace uses a png bookmark, not a favicon ico…

I guess that rule could be removed altogether as all other rules have the “file not exists” predicate anyways.

I dont have access to virtualhost config, its a shared host. I have tried to put my rewritelog in the htaccess file (that should work in apaches versions below 2.0) but it seesm its disabled;

.htaccess: RewriteLog not allowed here 

I still think its the rewrite base that should be different, but am stuck with trial and error withotu debugging…

You know, one simple way around the ‘double content’ issue is to use a canonical link in your header, which is what Google recommends. For their own purposes they say they’re pretty good at figuring out that it’s the same page but you can just do this all the same.

Thanks, I know, but its not fun to just let go bc inadequate mod-rewrite knowledge ;-) I’d really like to figure it out as outlined.

Also as a good practice, convenience, I’d really like to vote for this to be a setting of the install configs again, as Nils outlined. BC also then all extensions that modify the file should be compatible, not break it.

I don't know if the problem with the language redirect is already solved, but I tried the first solution, and it works:

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

I add this rule after the favicon rule.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details