Forum Moderators: phranque

Message Too Old, No Replies

Difference between Apache 1.3 vs. 2.0.46 mod rewrites

what changed with mod_rewrite between these versions?

         

relaxedguy

2:05 am on Mar 25, 2007 (gmt 0)

10+ Year Member



I needed to remove the .php suffix and the day of the month from uri's when I migrated my Movable type blog to wordpress.

This does exactly what I wanted in Apache 1.3.33, which is running on my laptop, but fails with a 500 error at my host, which is running Apache 2.0.46.

I think something changed with the mod_rewrite rules between versions of Apache, can't figure out what's wrong, anyone have any idea?

RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.*)\.php$ http://example.com/archives/$1/$2/$4 [R]

I am running a plug-in on Wordpress that does a redirect which removes the www in front of my domain name. This could be an issue as well, don't have that running on my laptop.

Mod_rewrite is amazing, but amazing how awful the Apache documentation is, this site is a great resource.

[edited by: jdMorgan at 2:15 am (utc) on Mar. 25, 2007]
[edit reason] Example.com. Please see TOS. [/edit]

jdMorgan

2:21 am on Mar 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is more likely a difference in the default Options settings between your host and dev environments. The only major change to mod_rewrite between Apache 1.3x and Apache 2.x from a user perspective was the addition of a RewriteRule flag [C] to set a cookie.

I'd suggest adding


Options +FollowSymLinks

ahead of your

RewriteEngine on

directive if it's not already present.

If that doesn't help, then take a look at your server error log for the cause of the 500 error -- It's usually explicitly identified in that log.

Jim

relaxedguy

8:44 pm on Mar 25, 2007 (gmt 0)

10+ Year Member



Good point, I added Options +FollowSymLinks.

Now, when I load the page, the CSS is not downloaded and I get this:

"mod_rewrite: maximum number of internal redirects reached"

<snip>

Here is my full htaccess file, there may be other problems with it that is affecting the mod_rewrite situation?

AddHandler cgi-script .cgi
Options +ExecCGI
# added 12-5-06 for Drupal
php_value memory_limit 16M

#DefaultType application/x-httpd-php
<FilesMatch "\.(php¦html)$">
SetHandler php4-script
</FilesMatch>

Options +FollowSymLinks

DirectoryIndex index.php index.html

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d

# Apache (version 2.0.46)

#RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.*)\.php$ http://example.com/archives/$1/$2/$4 [R]

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

AddHandler php5-script .php

[edited by: jdMorgan at 9:40 pm (utc) on Mar. 25, 2007]
[edit reason] example.com -- Please see Terms of Service. [/edit]

relaxedguy

2:33 pm on Mar 28, 2007 (gmt 0)

10+ Year Member



Sorry about leaving in my domain name, that was not on purpose. I've posted to the Wordpress support site about the redirect issue. WP does some sort of internal redirects as well, which may be adding to the problem, surprised this isn't sorted out yet, should be pretty common if you move from Movable Type to Wordpress and want to maintain proper redirects from old blog to new. I continue along the path to mod_write enlightenment.

jdMorgan

4:56 pm on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've commented-out the first RewriteRule. As such, the RewriteConds at the top now apply to the first non-commented-out rule that follows them. Is that what you intended?

Those RewriteConds allow the first rule after them to execute only if the requested URL resolves to a filepath that does not exist as a file and does not exist as a directory.

Use the "Live HTTP Headers" Firefox extension to investigate exactly what is going on, and with which specific URL requests.

Jim

relaxedguy

7:06 pm on Mar 28, 2007 (gmt 0)

10+ Year Member



I uncomment my rewrite line, then the CSS doesn't load and I get the too many redirects, then I comment it back out again.

I have livehttpheaders installed in Firefox, nice app, trying to make sense of the results.

Wordpress automatically sticks a few lines of redirects in the htaccess code. I tried to add mine in the middle of it, just to see if it would work.

I got another hint to try changing my [R] into an [R,L]. Or possibly an [R=301,L].

I thought there could only be one [L], which would be output by Wordpress as you can see from my earlier post.

Strange that it works on my laptop fine.

jdMorgan

9:05 pm on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to tell you that you can't just insert or remove a RewriteRule right after RewriteConds.

Those RewriteConds "belong" to the single RewriteRule that follows them.

If you delete that RewriteRule, or comment it out as you have done, then those RewriteConds will be applied to the NEXT rule.

This is programming here, and you can't just insert or remove stuff willy-nilly.

If you want to comment-out a RewriteRule, you must also comment out all the RewriteConds that precede it and belong to it.

---

Try completely flushing the browser cache on both machines -- I think you will then see identical results. To my knowledge, the only significant change to mod_rewrite between Apache 1.3.x and Apache 2.x is the addition of the [C] flag that allows a RewriteRule to directly set cookies.

Jim