Forum Moderators: phranque

Message Too Old, No Replies

Can't get non-www redirect to work on one specific site.

Same code works for two other sites, not this one.

         

Perfection

1:53 am on Dec 20, 2006 (gmt 0)

10+ Year Member



I'm trying to redirect www.domain-name.com/index.html to www.domain-name.com/

and

I'm trying to redirect all non-www pages to their www pages (domain-name.com redirects to www.domain-name.com).

I actually asked how to do this a few months ago in this very forum. I used what I was told and it worked perfectly fine for two other sites. Today I copy and pasted the same code, edited the domain name, and uploaded it to a third site. It caused every request to the site to do this:

Forbidden
You don't have permission to access / on this server.
Apache/1.3.27 Server at www.domain-name.com Port 80

This is the code I used:

IndexIgnore *

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ [domain-name.com...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.domain-name\.com
RewriteRule (.*) [domain-name.com...] [R=301,L]

I contacted my web host, and they claim "this can't be done because non-www and www are the same." They are obviously wrong, but I'm still unsure of how to get this to work and/or what's causing it not to work.

Any ideas? Thanks in advance.

[edited by: Perfection at 2:05 am (utc) on Dec. 20, 2006]

jdMorgan

2:22 am on Dec 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it the same host as the other sites and the same type of account?

If you have access to the server error log, look at it after testing and getting an error -- The information in the error log is often quite helpful. For example, if you need to adjust the RewriteBase to work with this host, the error log will often indicate how it needs to be adjusted.

If you have no server error log access, and the hosting co. won't help, then maybe consider a different host...

Jim

Perfection

2:45 am on Dec 20, 2006 (gmt 0)

10+ Year Member



Is it the same host as the other sites and the same type of account?

It's a different host. I'm not sure what you mean by account, but it's a shared hosting account. The other sites are shared hosting as well.

If you have access to the server error log, look at it after testing and getting an error -- The information in the error log is often quite helpful. For example, if you need to adjust the RewriteBase to work with this host, the error log will often indicate how it needs to be adjusted.

I just emailed my host to enable error logs. I actually just moved this domain here today (same host, just a different server) and didn't even get around to that yet. As soon as there are error logs, I'll let you know.

Thanks for your help.

Perfection

2:50 am on Dec 20, 2006 (gmt 0)

10+ Year Member



Here's something I just noticed, although I'm not sure if it is the cause or not.

In my control panel (which is completely new to me as of a few hours ago) there is something listed as "Modperl for Apache" that is currently NOT enabled for my account.

By any chance, could the fact that this is currently disabled be the cause?

jdMorgan

4:16 am on Dec 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, not likely. Mod_perl handles PERL-language server-side script processing.

You may want to compare file and directory permission settings between the "working" and "non-working" servers as well.

Jim

Perfection

1:50 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



Here's what the error log says:

[Wed Dec 20 06:39:40 2006] [error] [client ##.###.###.###] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /home/virtual/site5/fst/var/www/html

Any ideas? Thanks again.

skylla

2:35 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



have you tried to enable that option, eg:

Options +FollowSymLinks
RewriteEngine on

etc.

jdMorgan

2:35 pm on Dec 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there is the exact problem:

Options FollowSymLinks or SymLinksIfOwnerMatch is off

Add the following line to your code before "RewriteEngine on":


Options +FollowSymLinks

Jim

Perfection

3:15 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



I added exactly what you guys said to add. My .htaccess file looked like this:

IndexIgnore *
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/
RewriteRule index\.html$ [domain-name.com...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.domain-name\.com
RewriteRule (.*) [domain-name.com...] [R=301,L]

Then I went to the site and... still forbidden. I checked the error logs and it still says:

"Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden."

What's that about?

Perfection

3:35 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



I just tried using:

Options +SymLinksIfOwnerMatch
instead of
Options +FollowSymLinks

and... it worked! Nothing is forbidden, and everything redirects correctly.

Although, I'm not really sure what any of this stuff means or does, so I don't know if this is good and safe to have done, or if this just actually is the right way to do it.

So is this, okay?

jdMorgan

4:09 pm on Dec 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Only thorough testing can answer your question.

It seems very odd that FollowSymLinks does not work, while SymLinksIfOwnerMatch does. Did you flush your browser cache after making the first change? If not, you might want to re-test. You should flush your browser cache before testing *any* change to httpd.conf, conf.d, or .htaccess. Otherwise, your browser may show you stale previously-cached results.

SymLinksIfOwnerMatch is more restrictive and "secure" than FollowSymLinks, so the only concern here would be that the rewriterules may not be applied under certain circumstances when you would want them to be applied.

Jim

Perfection

4:22 pm on Dec 20, 2006 (gmt 0)

10+ Year Member



Only thorough testing can answer your question.

It seems very odd that FollowSymLinks does not work, while SymLinksIfOwnerMatch does. Did you flush your browser cache after making the first change? If not, you might want to re-test. You should flush your browser cache before testing *any* change to httpd.conf, conf.d, or .htaccess. Otherwise, your browser may show you stale previously-cached results.

Not only did I do that, but I used different browsers just to be extra sure that wasn't the case. I used Firefox, IE, and Netscape, and they all worked correctly with SymLinksIfOwnerMatch, and they were all forbidden with FollowSymLinks.

SymLinksIfOwnerMatch is more restrictive and "secure" than FollowSymLinks, so the only concern here would be that the rewriterules may not be applied under certain circumstances when you would want them to be applied.

Can you give me an example of this type of circumstance? I will only be using htaccess to redirect non-www to www, and index.html to /. Nothing else at all.

Thanks again for all your help, by the way.