Posts: 7
Threads: 4
Joined: Jul 2017
Reputation:
0
Sex: Undisclosed
Thanks: 2
Given 0 thank(s) in 0 post(s)
www to non www redirection
04-27-2018, 04:50 PM
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
Posts: 7
Threads: 4
Joined: Jul 2017
Reputation:
0
Sex: Undisclosed
Thanks: 2
Given 0 thank(s) in 0 post(s)
RE: www to non www redirection
04-30-2018, 06:21 PM
(This post was last modified: 04-30-2018, 06:30 PM by JSmith.)
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)?
Posts: 3 ,666
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 600 thank(s) in 465 post(s)
RE: www to non www redirection
05-01-2018, 12:48 PM
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
-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
Posts: 7
Threads: 4
Joined: Jul 2017
Reputation:
0
Sex: Undisclosed
Thanks: 2
Given 0 thank(s) in 0 post(s)
RE: www to non www redirection
05-03-2018, 11:19 PM
(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):
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:
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
The module is up and running. Both
and calling
tell me that rewrite_module is loaded.
Posts: 3 ,666
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 600 thank(s) in 465 post(s)
RE: www to non www redirection
05-04-2018, 07:15 AM
(05-03-2018, 11:19 PM)JSmith Wrote: 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
Posts: 10
Threads: 1
Joined: Sep 2017
Reputation:
0
Sex: Male
Thanks: 0
Given 0 thank(s) in 0 post(s)
RE: www to non www redirection
08-10-2018, 04:54 PM
(This post was last modified: 08-10-2018, 04:54 PM by yusha.)
Guys you can have a look on my post here. ( http://forums.sentora.org/showthread.php?tid=10120) I have posted the solution there.
|