Link to home
Start Free TrialLog in
Avatar of rbichon
rbichon

asked on

mod_rewrite not working with PHP files!

I created an .htaccess file to redirect people connecting to my site from a PDA to a pda version of the site. If they try to connect to http://www.domain.com/index.html, it will redirect them to http://www.domain.com/pda/index.html. It works well with all of the file types accept my php pages. When I try to connect to a php page, I get a 404 error. Can someone help me? Here is my code:

<Files 403.shtml>
order allow,deny
allow from all
</Files>

ErrorDocument 404 /404.htm

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI} !^/pda/.*$ [NC]
RewriteRule ^(.*) /pda/$1 [L,R]
Avatar of sleep_furiously
sleep_furiously

Since you are doing an external redirection (sending a new address to the browser and telling it to go there), you should test the PHP pages without going through the rewrite.  (e.g. go directly to http://www.domain.com/pda/index.php ).  Do the PHP pages work when you use the "pda" version of address to begin with?  If not, the problem is your PHP config and not mod_rewrite.

Avatar of rbichon

ASKER

The php pages work fine if I have a blank .htaccess file in place. Once I put this up, they stop working. I have this exact same .htaccess file on several other Linux servers and none of them have any issues with it in regards to php pages. Unfortunately, I do not have access to change and of the Apache config files as I am working with a remote server. Any other suggestions?
ASKER CERTIFIED SOLUTION
Avatar of rama_krishna580
rama_krishna580
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rbichon

ASKER

I am able to rewrite from one folder to the next without any problem as long as the first folder is not the root folder. The problem comes in when I try to rewrite from the root folder to the pda folder. But again, the problem only comes in when it involves php files. HTML files rewrite just fine.

I have a fix that seems to work. I have written a php redirect file that I include in each php page on the site that does a redirect under the same conditions. Then I rewrote the .htaccess file to redirect only html files. Here is the new .htaccess code:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "NetFront" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Palm OS" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Plucker" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC]
RewriteCond %{REQUEST_URI} ^/.*\.(htm|html)$ [NC]
RewriteCond %{REQUEST_URI} !^/pda/.*\.(htm|html)$ [NC]
RewriteRule ^(.*)\.(htm|html) /pda/$1\.$2 [L,R]

I am assuming that my problem is due to some difference in server configurations surrounding php and apache.