We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Redirect non-www to www? | Forum

Topic location: Forum home » Support » General Questions
Marcus
Marcus Nov 17 '14
I am trying to redirect my non-www URLs to www but for some reason all URLs get redirected to example.com/index.php

Here is my code:

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

The Forum post is edited by Marcus Nov 17 '14
Marcus
Marcus Nov 18 '14
The problem is that it redirects to index.php
ross Team
ross Nov 18 '14
where do you want to redirect it to?which solutions you tried from the search?
The Forum post is edited by ross Nov 18 '14
Marcus
Marcus Nov 18 '14
Here is the code of my htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} !/e500\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php

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


Now the problem is that when I access http://example.com/users it redirects to http://www.example.com but suppose to redirect to http://www.example.com/users

Please how to fix that?
ross Team
ross Nov 18 '14
 you added only rewrite rule and condition for non www to be Haven't you considered to put Users page as a first page of your website here: www.yoursite.com//admin/pages/manage ?
Marcus
Marcus Nov 18 '14
I don't understand please explain a bit more.

I mean no matter what page I visit if the URL is non-www it redirects to root like www.example.com


ross Team
ross Nov 18 '14
Please read this manual: http://docs.oxwall.org/user-manual:pages-and-menus

You can drag and drop and change the order of you pages. 

Marcus
Marcus Nov 18 '14
I don't think it has something to do with pages. The problem is in the redirect itself.

This part is causing the issue: RewriteRule (.*) index.php
ross Team
ross Nov 19 '14
Marcus, please provide a screenshot of this page in your admin panel: http://demo.oxwall.org/admin/pages/manage
Marcus
Marcus Nov 20 '14
Thanks Ross the issue had been fixed thanks a lot

ross Team
ross Nov 20 '14
Can you please tell us what was the reason of the issue and how you solved it?
JoshWho
JoshWho Aug 17 '15
The answer is :


He had the RewriteRule under all the other ones. Like So


RewriteEngine OnRewriteCond %{REQUEST_URI} !^/index\.php

RewriteCond %{REQUEST_URI} !/ow_updates/index\.php

RewriteCond %{REQUEST_URI} !/ow_updates/

RewriteCond %{REQUEST_URI} !/ow_cron/run\.php

RewriteCond %{REQUEST_URI} !/e500\.php

RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]

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





If he put the Rewrite Rule First in the list then everything will work correctly. Like So

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

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} !/e500\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php


The Forum post is edited by JoshWho Aug 17 '15