PDA

View Full Version : 301 Redirect from non-www To www URL (real estate)



PGGO
June 29, 2012, 07:03 PM
I'm wondering how I can perform 301 redirect from ‘non-www’ to ‘www’ URLs in Real Estate.
I want all my URLs to be with ‘www’ prefix.

Thanks.

Parasca Iulian eugen
June 29, 2012, 07:51 PM
you can use .htaccess file if the script it not doing this allready

---- .htaccess file example ----
RewriteEngine On

#force non-www to www

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

#force non-ssl to ssl

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

---- .htaccess file end example ----

T.Bogdan
SysAdmin

PGGO
July 1, 2012, 12:22 AM
It does not work for version 4.0.
I'm not even able to access my website with ‘www’ prefix.

Parasca Iulian eugen
July 1, 2012, 11:25 AM
then the problem may be elsewhere

first you must check that your host www config is ok ( if you use a vhost then ask your sys admin to check it ). That mean anything you put in your site directory can be accesed by your calling desire hostname. So if your www directory is for examble /home/your-user/public-www and you put there a file called my-file.html then you call that file http://www.your-host.org/my-file.html the response must be positive. If you can call your file only by http://your-host.org/my-file.html and with http://www.your-host.org/my-file.html not then the problem is in the virtualhost config and you ( or your sysadmin ) must config the virtualhost properly

T.Bogdan
SysAdmin

PGGO
July 2, 2012, 06:18 PM
Thanks Bogdan for your suggestion; however, I’m not sure how to perform such changes.

I checked ‘index.php’ file in root directory, and have found the code below.
Does this may cause this issue?



/* www prefix detecting */
$redirect_host = explode('/', RL_URL_HOME);
$redirect_host = 'http://'.$redirect_host[2].'/';

if ( false === strpos($_SERVER['HTTP_HOST'], 'www') && false != strpos(RL_URL_HOME, 'www') )
{
$request_url = ltrim($_SERVER['REQUEST_URI'], '/');
header("Location: ". $redirect_host . $request_url);
}
elseif ( false !== strpos($_SERVER['HTTP_HOST'], 'www') && false === strpos(RL_URL_HOME, 'www') )
{
$request_url = ltrim($_SERVER['REQUEST_URI'], '/');
header("Location: ". $redirect_host . $request_url);
}

Viktor
July 3, 2012, 05:17 AM
Hello Petnax,

If you want use your site with www and system should redirect you to www you can go to:
ftp:includes>>config.inc.php
find line:

define( 'RL_URL_HOME', 'http://your_site.com');

add www. in your site name.

PGGO
July 5, 2012, 07:04 AM
Viktor,
Thanks for the info, it works!

In addition, I have notice a ‘302 redirect‘ from non-www to www.
Q: can I add a ‘301 redirect’ instead of 302 ?

It will help for SEO a bit.

Viktor
July 10, 2012, 04:42 AM
Hello Petnax,

Please open file ftp://index.php
find:


/* www prefix detecting */
$redirect_host = explode('/', RL_URL_HOME);
$redirect_host = 'http://'.$redirect_host[2].'/';

in top of file and after it add new:


header( "HTTP/1.1 301 Moved Permanently" );
I think it should solve it :)

PGGO
July 18, 2012, 04:26 AM
in top of file and after it add new:


header( "HTTP/1.1 301 Moved Permanently" );


Viktor,

Would you please explain more detailed?
Cause, it’s not clear to me, at which line I should add this line of Code “header( "HTTP/1.1 301 Moved Permanently" );”

Mike
August 8, 2012, 10:11 AM
Hi,

Easiest thing is to have domain name with www in the includes/config.inc.php file

Then system will redirect all pages to www.

in addition to this you can put rewrite rule to htaccess file



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

4.1 software version asks how you want your website to be - with www or without during installation

Giuseppe Mollo
June 3, 2016, 12:36 PM
I try with htaccess, in my ftp:includes>>config.inc.php i have the www, but still doesen t work. i want to redirect from http://example.com to http://www.example.com. Thanks!