URL rewriting interfering with another app?

Creating and modifying plugins.
Hathor
Regular
Posts: 118
Joined: Tue Mar 22, 2005 11:48 pm

Post by Hathor »

I found a solution for this after a LOT of trial and error and searching online. It's almost embarrassingly simple. And it works not just between Serendipity and other apps... almost any two php scripts, one in a subfolder under the other, can have clashing rewrite rules.

My serendipity blog is in the main folder at BlueMushrooms.com. The rewrite rule I had added in was this:
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^bluemushrooms\.com$
RewriteRule (.*) http://bluemushrooms.com/$1 [R=301,L]
That makes it so that if people type "www.bluemushrooms.com", it will load as "bluemushrooms.com". This may not matter to average bloggers, but if you want your site to rank well in Google, it's very important, because Google counts the www and non-www version as two domains and penalizes you. (Which is, IMHO, ridiculous, but what can ya do?)

Now, the PROBLEM was, I had a directory in a subfolder. S9's rewrite rules were clashing with the subfolder's rewrite rules, so I had no choice but to put a "RewriteEngine Off" in the subfolder's htaccess. Still with me? :)

But that meant people typing in "www.bluemushrooms/directory" would get the www version, which is not a Google happy situation.

Here's the solution. This is the htaccess in my SUBFOLDER that makes everything work. Notes in red explain step by step what's being accomplished:
RewriteEngine Off (turns off S9's clashing rewrite rules)
#lmasetting (settings the subfolder script needs to function)
<files directory>
ForceType application/x-httpd-php
</files>
#lmasettingend

RewriteEngine On (turns rewrite back on for subfolder)
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^bluemushrooms\.com$
RewriteRule (.*) http://bluemushrooms.com/[b]directory/[/b]$1 [R=301,L]
(this is the key line that tells it where to redirect people who use "www". By sticking my subfolder at the end (bold), each folder gets the appropriate redirection to work the way I want)
mark_macinnes
Posts: 2
Joined: Sat Oct 22, 2005 10:59 am
Contact:

RewriteEngine Off Not Working

Post by mark_macinnes »

I've been trying to use a subdirectory without the blog from redirecting me. I've created a .htaccess file in the subdirectory. It's contents are:
RewriteEngine Off

But this isn't working.

This is the link:
http://www.awake-and-dreaming.co.uk/test/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: RewriteEngine Off Not Working

Post by garvinhicking »

What file are you requesting in your /test/ subdirectory? Di dyou put a index.html there, or what?

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/
mark_macinnes
Posts: 2
Joined: Sat Oct 22, 2005 10:59 am
Contact:

Post by mark_macinnes »

I was requesting a index.html file.

I've changed from using mod_rewrite to using Apache errorhandling and everything is working fine now.
Post Reply