PDA

View Full Version : htaccess, wordpress, "www", and ie/firefox



tre
12-14-2007, 05:42 PM
hi, i need advice please! major weirdness for me

my domain is setup with wordpress. one of the plugins i use required a 2 line modification to htaccess - and here is the result:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^calendar/([^/\.]+)/([^/\.]+)/?$ wp-calendar.php?year=$1&month=$2 [QSA,L]
RewriteRule ^calendar/?$ wp-calendar.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress


so ok - in firefox now, both www.mydomain.com/calendar & mydomain.com/calendar work (without redirecting which is a problem afaik)

and in IE - the most confusing behaviour has me really confused, sometimes www works, sometimes without works, sometimes neither (only when dealing with the /calendar though)

bottom line i guess is -> can someone help me to ensure that my domain redirects all traffic to the url WITHOUT www, and could work in all browsers...?

I appreciate any advice, thanks, tre
the pages work in firefox - but not IE, either 6 or 7. if i manually enter the www in the url, then it works

Basil
12-15-2007, 12:30 AM
htaccess is server-side and has little to do with what browser you use. I'd say it was the cache but that wouldn't explain two different browsers not working.

You can try flushing the cache in those browsers and restarting them, probably wouldn't hurt to run "ipconfig /flushdns" from run (windows key + R).

tre
12-15-2007, 09:29 AM
thanks for that suggestion.

i have found out that the server is sending a 404 status, along with the correct page data.

firefox displays the page data anyway, whereas IE shows it's internal 404 page.

question is: why is the server throwing a 404 along with the page?

is it a mistake in the htaccess rules...?
i am far from understanding the htaccess voodoo ;)

what is supposed to happen, is that whan a url like http://mydomain/calendar/2007/jan is sent as request, htaccess is supposed to translate that to
http://mydomain/wp-calendar.php?year=2007&month=jan

which it actually IS doing, but the server decides to throw a 404 with it

thanks again if anyone has some more advice.
tre

Basil
12-15-2007, 10:57 AM
Lazynitwit's got this.

lazynitwit
12-15-2007, 11:56 AM
This appears to be happening because of how Wordpress handles rewrites, the following is a quick hack I put together to get rid of the 404-error status code. I cannot say whether this is a good approach to fix this as I do not know much about how Wordpress works:

You might wish to backup your files before attempting this.

In the file wp-includes/classes.php look for:

// If req_uri is empty or if it is a request for ourself, unset error. This should be around line 130.

Above this line add the following:

if (!empty($request_match) &&
(preg_match("!^calendar/?$!", $request_match) ||
preg_match("!^calendar/([0-9]+)/([a-z]+)/?$!", $request_match))) {
unset($error);
unset($_GET['error']);
return;
}

and save the file.

If anyone knows of a better method for this I'd be glad to hear it because I got rather annoyed with Wordpress looking into this.

Basil
12-15-2007, 01:07 PM
You didn't mention the part about it being a 404 on the plugin-creator's website ^_^

tre
12-15-2007, 03:56 PM
that's great, thanks. i'll try it out

i actually tried using php header() function to force a "200 OK" like this:

<?php
header("HTTP/1.0 200 OK");
?>

but i couldn't get it working yet

ya, i'm newer to php, and htccess too, and yes, the bluehost forums are great.

lastly - i didn't mention about the author's own site cause i wanted a working solution first, but i was going to mention it to him ;)

tre
12-15-2007, 04:26 PM
i get a returned error page saying,

"The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

and also, whe i tried to go to http://mydomain/calendar, the url gets chaged in theaddress bar to http://mydomain/wp-calendar.php (and it displays the error above)

i'm going to keep trying away at it though, and i appreciate what you have shown me there.
/tre

tre
12-22-2007, 11:32 AM
Just wanted to update this -

It's working, I used your code for classes.php (thanks), but i had to edit my htaccess and remove the couple lines that strip out the www.

Somehow it works and STILL strips out the www - ???

Makes me wonder if bluehost strips out the www from my url somewhere higher up the chain? Because in my root folder, and the root folder of the subdomain, there is no code that should do that, and yet it still does --> ???

And, it has one exception - for the URL of the calendar ONLY, it will accept both www, and no www, without stripping it out, but all other URL's it strips it.

i can live with this - but it would be great to have some knowledge on why this happens.

my htaccess now looks like this:


Options +FollowSymlinks
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^calendar/([^/\.]+)/([^/\.]+)/?$ wp-calendar.php?year=$1&month=$2 [QSA,L]
RewriteRule ^calendar/?$ wp-calendar.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Thanks for the help, peace