This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

www to non www redirection
#1
www to non www redirection
Similar thread (ZPanel)

I'm having problems redirecting two of my subdomains from www to non www. I've setup CNAME entries, and created .htaccess with the following content:


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


and placed them in proper subdomain directories.

However, whenever I type www.mysubdomain.mysite.com, I'm redirected to Sentora login page. I'm guessing that something takes precedence over the rules I've setup, but I'm unsure how to fix it.

I was thinking of making changes in httpd-vhosts.conf, through Sentora admin panel, and setting the redirections there, but I'm unsure whether that would solve my problems.

This redirection is needed, because I have users who keep typing (or calling it from their bookmarks) the www prefix.

Server info:
Code:
Dedicated server
Server OS: CentOS Linux release 7.4.1708 (Core)
Apache Version: 2.4.6
PHP Version: 5.6.35
MySQL Version: 10.2.14-MariaDB
Sentora Version: 1.0.3
Reply
Thanks given by:
#2
RE: www to non www redirection
Doing

Code:
cat /etc/sentora/configs/apache/httpd-vhosts.conf

returns this

Code:
################################################################


# DOMAIN: subdomain.mysite.com
<virtualhost *:80>
ServerName subdomain.mysite.com
ServerAdmin zadmin@localhost
DocumentRoot "/var/sentora/hostdata/zadmin/public_html/subdomain_mysite_com"
php_subdomain_value open_basedir "/var/sentora/hostdata/zadmin/public_html/subdomain_mysite_com:/var/sentora/temp/"
php_subdomain_value suhosin.executor.func.blacklist "passthru, show_source, shell_exec, system, pcntl_exec, popen, pclose, proc_open, proc_nice, proc_terminate, proc_get_status, proc_close, leak, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, escapeshellarg"
ErrorLog "/var/sentora/logs/domains/zadmin/subdomain.mysite.com-error.log"
CustomLog "/var/sentora/logs/domains/zadmin/subdomain.mysite.com-access.log" combined
CustomLog "/var/sentora/logs/domains/zadmin/subdomain.mysite.com-bandwidth.log" common
<Directory "/var/sentora/hostdata/zadmin/public_html/subdomain_mysite_com">
  Options +FollowSymLinks -Indexes
  AllowOverride All
  Require all granted
</Directory>
AddType application/x-httpd-php .php3 .php
DirectoryIndex index.html index.htm index.php index.asp index.aspx index.jsp index.jspa index.shtml index.shtm
# Custom Global Settings (if any exist)

# Custom VH settings (if any exist)

</virtualhost>
# END DOMAIN: subdomain.mysite.com
################################################################


Since this is a file automatically generated by Sentora, is there a way for me to edit this part:

Code:
<Directory "/var/sentora/hostdata/zadmin/public_html/subdomain_mysite_com">
 Options +FollowSymLinks -Indexes
 AllowOverride All
 Require all granted
</Directory>


so that it includes the rules I'd originally placed in .htaccess?

Also, will this edit provide what I'd originally intended to do (www to non www)?
Reply
Thanks given by:
#3
RE: www to non www redirection
Did you set up a DNS entry for www.subdomain.domain.com? If any sub domains (or in this case sub-sub domains) do not have the proper DNS entry it will point to the panel login because it can not find the sub-sub domain. (www is considered a sub domain believe it or not, that gets directed to point to your domain folder.)

I use this for a non-www to www redirect in my .htaccess (apache 2.4):
Code:
RewriteEngine On

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So, for www to non-www should be something like this:
Code:
RewriteEngine On

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

In either case, check your php config to ensure mod_rewrite is enabled or it will never work Wink
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#4
RE: www to non www redirection
(05-01-2018, 12:48 PM)TGates Wrote: Did you set up a DNS entry for www.subdomain.domain.com? If any sub domains (or in this case sub-sub domains) do not have the proper DNS entry it will point to the panel login because it can not find the sub-sub domain. (www is considered a sub domain believe it or not, that gets directed to point to your domain folder.)

Interesting bit about www being a subdomain, I never would've guessed that. As for the DNS entry, I've set it up like this (outside of Sentora, through my user account):

[Image: csRBQKY.png]

I've tried setting the CNAME from within Sentora's control panel, but the DNS manager doesn't offer anything for the two of my subdomains, only for the domain. Even tried doing something silly, like trying to create (in Sentora panel) a subdomain like this:

[Image: sjLGrCj.png]

thinking that it just might create a sub-subdomain, with the directory placed neatly in public_html. But, of course, that didn't work.

(05-01-2018, 12:48 PM)TGates Wrote: In either case, check your php config to ensure mod_rewrite is enabled or it will never work Wink

The module is up and running. Both

Code:
httpd -M

and calling

Code:
<?php phpinfo(); ?>

tell me that rewrite_module is loaded.
Reply
Thanks given by:
#5
RE: www to non www redirection
(05-03-2018, 11:19 PM)JSmith Wrote: [Image: csRBQKY.png]
The CNAME records should not include the entire URL... just the www part. What you are asking it to do is go to www.subdomain.mysite.com.subdomain.mysite.com
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#6
RE: www to non www redirection
Guys you can have a look on my post here. (http://forums.sentora.org/showthread.php?tid=10120) I have posted the solution there.
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
redirection domain marketingdigitalmassivo 3 7 ,722 07-20-2016, 07:38 PM
Last Post: Me.B
webmail redirection not working surfnode 18 46 ,288 03-21-2015, 10:10 PM
Last Post: kini
Redirection help please. parked domain does not work!! artdenic 10 30 ,484 03-08-2015, 08:54 PM
Last Post: Ron-e

Forum Jump:


Users browsing this thread: 1 Guest(s)