Simple redirect not working...

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
939
22
168
Could anyone spare a minute to offer some advice ? The redirect looks fine to me but just doesnt work.
 

NexGenUK

Active Member
May 7, 2004
35
0
156
Its actually due to apache being difficult - if you are redirecting to a directory, apache will force another redirection to ensure there is a trailing "/" to the folder:
eg if i visit:
http://www.randomdomainusingapache.com/folder
apache will redirect it to the ServerName /folder/
in this instance it would redirect to http://randomdomainusingapache.com/folder/

this is due to the fact that www.{domain} is setup as an alias and the plain old domain is setup as the ServerName:

httpd.conf extract:
ServerAlias www.domain.com
ServerAdmin [email protected]
DocumentRoot /home/domain/public_html
User domain
Group domain
ServerName domain.com
This is not something that cPanel can inherently fix because its apache that is governing this.
 

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
939
22
168
Its actually due to apache being difficult - if you are redirecting to a directory, apache will force another redirection to ensure there is a trailing "/" to the folder:
No, its not that but it has something to do with slashes.

The same issue happens when redirecting to a file....

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ http://www.myotherdomain.com/redirect.html [R=301,L]

In this instance, if you enter the first domain in a browser it simply redirects to myotherdomain.com instead of going to redirect.html

I notice the redirect DOES work if you enter mydomain.com/ or anything after the forward slash.

So...

mydomain.com or www.mydomain.com do not work.
mydomain.com/ or www.mydomain.com/ does work

Performing a forced upcp has not fixed this issue. The server is using release build.

Is there something I need to add in the httpd.conf file to correct this ?

It seems that the redirect isnt working because apache ISNT automatically adding the slash.
 
Last edited:

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
939
22
168
Here is another example...

This customer has two accounts with us.

On an older server, this mod_rewrite directive works fine - on one of the new ones it doesnt. Bear in mind that we have not made any changes to the apache configuration on either of these servers - they are standard Cpanel release build servers - both are running the same build. The only difference is that one is 3 years old, the other is about 3 weeks old.

RewriteRule ^categories/([^/.]+).html?$ index.php?category=$1 [L]

This rule takes a page named for example weddings.html and re-writes it to index.php?category=weddings


On the new server it just attempts to go to weddings.html which doesnt exists so a 404 is produced. Its as though the htaccess file is being ignored.
 

4u123

Well-Known Member
PartnerNOC
Jan 2, 2006
939
22
168
Anyone have any ideas before I log a ticket with cpanel ?
 

sabarishks

Active Member
Jun 29, 2007
35
0
56
.htaccess to .htaccess.bak

Please try moving .htaccess to .htaccess.bak.........

Just a try to narrow down the issue.