Forum Moderators: phranque
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]
I'd suggest adding
Options +FollowSymLinks
RewriteEngine on
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
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]
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
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.
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