Forum Moderators: phranque

Message Too Old, No Replies

Redirect via httpd.conf or .htaccess?

         

Laibcoms

10:36 am on Jan 12, 2007 (gmt 0)

10+ Year Member



I've been reading and hearing that it is better to put the redirection in the httpd.conf than .htaccess, is it really recommended?

Coz if I do just that, I get into a few problems (mainly trivial).

Problem #1:
I have to put two VirtualHost for every domain and sub-domain manually.

Sample:


<VirtualHost 123.456.789.012>
ServerName sub.domain.tld
DocumentRoot ..../.../././././
User
Group
<VirtualHost>

<VirtualHost 123.456.789.012>
ServerName sub.domain.tld
Redirect 301 / http://sub.domain.tld
<VirtualHost>

Problem #2:
If I do the code above, all my sub-domains disappear from that "domain"'s cPanel list for its subdomains.

--
Is there a better way of doing redirection via httpd.conf, or say, a more effective way of doing it that will minimize performance load (vs .htaccess) and be friendly to search engines?

Thank you again.

Regards,
JCuneta.

jdMorgan

3:15 pm on Jan 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Code placed in httpd.conf is compiled once on server restart. The same code placed in .htccess is interpreted for each and every HTTP request to your server. Therefore, the CPU load is much less if the code is placed in httpd.conf or conf.d, or any other server config file, instead of .htaccess.

This is of no concern on a lightly-loaded server with very few directives in .htaccess. However, as your site gets popular, or the number of directives grows, efficiency will become more important. If you are serving fewer that ten responses per second, don't worry about it right now. For many configuration directives, you can use .htaccess to develop solutions and test them for several days, and then modify the code and move it into httpd.conf. The advantage of using .htaccess is that you don't have to re-start the server to re-compile the httpd.conf file after every change to your code.

I assume we're still talking [webmasterworld.com] about redirecting one subdomain to another? If so, there should be no need to define multiple vhosts. Try something like this:


<VirtualHost 123.45.78.9>
ServerName example.com
ServerAlias *.example.com
#
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub1\.example\.com
RewriteRule (.*) http://sub2.example.com$1 [R=301,L]
#
</VirtualHost>

Jim

Laibcoms

5:14 am on Jan 15, 2007 (gmt 0)

10+ Year Member



Hi,

Thanks for the reply!

Nope, not related to the redirection of sub-domain to another sub-domain, generally about keeping all "www." access to permanent redirect to a non-www domain avoiding .htaccess (hosting 4 sites on one box with several sub-domains).

I am using some applications that do not like being accessed from another domain name and I setup these apps without the "www" prefix. And I noticed from my logs, there are visitors and referrals that are typing the address with a "www" prefix, and this makes some of the apps (CMS, forums) not to load correctly.

Though when I start to touch sub-domains, they disappear from the cPanel subdomain list.

I will try your example. Thank you very much again.

Regards,
JCuneta.