Root level htacess and redirects issues

Having trouble installing serendipity?
Post Reply
vincem
Regular
Posts: 59
Joined: Sat Mar 05, 2005 6:01 am
Contact:

Root level htacess and redirects issues

Post by vincem »

I'm having an issue with redirects and htaccess. I'm trying to redirect any traffic arriving to mydomain.com to go to www.mydomain.com instead. The following is the code I'm using for that purpose in the root level htaccess file (I've changed my own domain name into "mydomain" below to avoid getting this crawled by Google and indexed as a weird link as it did before):

Code: Select all

Options +FollowSymlinks
RewriteEngine On
RewriteOptions MaxRedirects=10
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
However that causes a problem: if I navigate to www.mydomain.com/s9y/ (let's say that's my path to the Serendipity installation), everything works fine. However if I try to go to www.mydomain.com/s9y (without the trailing slash), the URL gets re-written as http://www.mydomain.com/cgi-bin/php5-cgi/s9y/index.php and that obviously doesn't work well. ;-)

I'm using mod_rewrite in Serendipity's settings because errorhandling, which I'm not too familiar with, was working and fixing that problem but also returning a "File does not exist" which I assume were 404's in the server's error log with every page load, even though the blog was loading fine in my browser.

As it is, my Serendipity htaccess file is unchanged from what is created by turning mod_rewrite on.

Just in case, here's my real s9y install: http://www.vincentmounier.com/blog2/ ; I have turned root level redirects off for now to avoid the conflict with Serendipity. That way I am having partial success: navigating to www.mydomain.com/s9y redirects me to mydomain.com/s9y/, which works but really isn't what I want...

I must be missing something obvious. How can I set Serendipity's htaccess to co-exist with my root-level redirects?

Cheers,
Vince
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Root level htacess and redirects issues

Post by garvinhicking »

Hi!

I believe this bad "/" redirection might come from a missing or malbehaving DirectoryIndex clause. I'm actually not sure why "s9y" does not instruct your webserver to go to "s9y/". Can you contact your server support to ask them about this specific issue?

If s9y were properly turned to "s9y/" then the HTTP redirection wouldn't fail...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
vincem
Regular
Posts: 59
Joined: Sat Mar 05, 2005 6:01 am
Contact:

Re: Root level htacess and redirects issues

Post by vincem »

I'm afraid server support were about as helpful as a post office employee. ;-)

I did check my DirectoryIndex setting and it is set to index.htm but I assume that's only for the root level. Can DirectoryIndex also handle sub-directories?

Updated: I conducted a test with another script in another similar directory and the results are the same, so it would seem that s9y's htaccess isn't directly responsible..

I'll keep looking. One last question: is it normal for the other mode available in Serendipity (Apache errorhandling) to return a "file not found" on the error log (for every GET it would seem), even though the page is loading fine?

Regards,
Vince
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Root level htacess and redirects issues

Post by garvinhicking »

Hi!

Yeah, I also don't think that DirectoryIndex might be the right setting. It might be some other canonical APache setting, that I'm not really aware of. Maybe a specific Apache/Webhosting-Forum could give more help on the issue?
I'll keep looking. One last question: is it normal for the other mode available in Serendipity (Apache errorhandling) to return a "file not found" on the error log (for every GET it would seem), even though the page is loading fine?
Yes, it is. Since it uses the ErrorHandling directive, you can't prevent an entry in the Apache errorlog in this case...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
vincem
Regular
Posts: 59
Joined: Sat Mar 05, 2005 6:01 am
Contact:

Re: Root level htacess and redirects issues

Post by vincem »

Well, whatever the cause was, I've solved my issue by adding a couple of lines to s9y's htaccess that basically duplicate the rewrite rules I had at root level. I'm not too sure about the rationale behind all this but it works...

Cheers,
Vince
abdussamad
Regular
Posts: 117
Joined: Fri Apr 21, 2006 10:11 pm
Location: Karachi, Pakistan
Contact:

Re: Root level htacess and redirects issues

Post by abdussamad »

I recommend that you use the following code just once:

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
Why change the code now? Well because no-www link to an entry permalink still does not redirect correctly on your site.
vincem
Regular
Posts: 59
Joined: Sat Mar 05, 2005 6:01 am
Contact:

Re: Root level htacess and redirects issues

Post by vincem »

Wow, I hadn't caught that, thanks for the feedback! I had to tweak your code a bit to fix another problem I just discovered, which was an error when rewriting to add both the "www" and the trailing "/", so I had to add more code to both my root and Serendipity .htaccess, but in the end I believe I've got it fixed.

Cheers,

Vince
Post Reply