Solved

mod_rewrite not working with PHP files!

Posted on 2006-06-16
4
554 Views
Last Modified: 2010-03-04
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]
0
Comment
Question by:rbichon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:sleep_furiously
ID: 16921865
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.

0
 
LVL 1

Author Comment

by:rbichon
ID: 16922240
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?
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 16972238
Hi,

try this...
http://www.phpfreaks.com/tutorials/23/0.php
http://www.phpfreaks.com/phpmanual/page/function.next.html

If you have a folder /foo/, you can't have both /foo/index.php and /foo/Rewrite very easily. It makes it much easier if you have /foo/Rewrite and /f/index.php. (Source: Wikimedia)
Here's the .htaccess for this wiki: <!-- --># /wiki/Title as an alias to /wiki/index.php?title=Title
RewriteEngine on

<!-- --># wiki pages
RewriteRule ^wiki/([^.]*)$ /w/index.php?title=$1 [L,QSA]

<!-- --># files in the wiki folder (e.g. images)
RewriteRule ^wiki/(.*)$ /w/$1 [L,QSA]

R.K
0
 
LVL 1

Author Comment

by:rbichon
ID: 16983048
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question