I've been battling some .htaccess rewrite issues lately for a webserver I provide with code provided to me externally by a consulting company. I've been chasing this issue from the perspective of 'rewrites do not work' however I think I've discovered that the actual problem is that rewrites are causing a white screen of death.
My site
http://it-news.awesome.net/news/it/153/coverstory/
my .htaccess
RewriteRule ^news/(.*)/(.*)/(.*)/$ news.php?department=$1&newsid=$2&newstitle=$3 [NE,L]
RewriteRule ^news/(.*)/(.*)/$ news.php?department=$1&archive=$2 [NE,L]
RewriteRule ^news/(.*)/$ news.php?department=$1&archive=0 [NE,L]
will produce the output URL
http://it-news.awesome.net/news.php?department=it&newsid=153&newstitle=coverstory
which is perfect. I can copy paste this from the rewrite tester tool here
into my browser and the articles open fine. Going to the main page and browsing the site (which has pretty URLS turned off currently) will have all these pages displaying and everything is OK.
The minute I try and use the
http://it-news.awesome.net/news/it/153/coverstory/
link, I'm hit with a white screen of death. I've stepped through the .htaccess file and commented out individually the matching lines and once there is no match, then I'm taken to my homepage and can browse normally.
I've further tested this by creating a test.php with the code
<?php
echo $_GET['var'].' "this is static text" '.$_GET['var2'];
?>
and creating a rewrite rule
RewriteRule ^(.*)/(.*)$ test.php?var=$1&var2=$2 [NC,L]
and this DOES work.
http://it-news.awesome.net/testvariable1/testvariable2/
outputs
testvariable1 "this is static text" testvariable2
as a webpage. I'm forced to conclude that
- my webserver rewrites work correctly
- php interprets the variables given from rewrites OK in SOME situations
but now I'm hopelessly stuck. I don't know where to begin testing or debugging php and I can't imagine why some php is going to fall down and whitescreen when it seems to be correctly interpreting variables from a rewrite and can open those pages OK without using rewrites.
Anyone come across this? I wonder if it's some PHP server config or something that I've missed.
update after the comments from Mike Rocket
further testing gets me to the following .htaccess. the top 4 lines referencing test.php are for testing only and the bottom 3 are the real hopefully working documents.
RewriteBase /
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^hello\.html$ redir.html
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
RewriteRule ^(wordpress|user)($|/) - [L]
RewriteRule ^(mysqladmin|user)($|/) - [L]
RewriteRule ^(admin|user)($|/) - [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ test.php?t1=$1&t2=$2&t3=$3&t4=$4 [NE,NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ test.php?t1=$1&t2=$2&t3=$3&t4=$4 [NE,NC,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ test.php?t1=$1&t2=$2&t3=$3&t4=$4 [NE,NC,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ test.php?t1=$1&t2=$2&t3=$3&t4=$4 [NE,NC,L]
RewriteRule ^news/(.*)/(.*)/(.*)/$ news.php?department=$1&newsid=$2&newstitle=$3 [NE,L]
RewriteRule ^news/(.*)/(.*)/$ news.php?department=$1&archive=$2 [L]
RewriteRule ^news/(.*)/$ news.php?department=$1&archive=0 [L]
my new test.php contains
<?php
echo 't1: '.$_GET['t1'].'<br/>';
echo 't2: '.$_GET['t2'].'<br/>';
echo 't3: '.$_GET['t3'].'<br/>';
echo 't4: '.$_GET['t4'].'<br/>';
?>
what I'm seeing is that for the test.php lines using http://testsite.website.com/test/test2/test3/test4/
is that the first 2 will produce broken output like this
t1: test.php/test2
t2: test3
t3: test4
t4:
and hashing out the top 2 lines, the second 2 lines in the test.php relevant section will give me the output I want.
t1: test.php
t2: test2
t3: test3
t4: test4
what I'm finding horrible here, is that my first variable 'test' coincidently has the same name as my php file itself and if that is the case, it's giving through the name of the php file as a variable instead of the word test.
this
http://testsite.website.com/test/test2/test3/test4/ produces
t1: test.php
t2: test2
t3: test3
t4: test4
but this
http://testsite.website.com/test1/test2/test3/test4/
produces this
t1: test1
t2: test2
t3: test3
t4: test4
and I have a feeling this is the root of my issue. In my live situation I have
my.website.com/news/it
calling a news.php file as well. So it's passing in 'news.php' instead of 'news' everytime. I feel like this isn't normal and I should be able to stop this from happening somehow...