Solved

mod_rewrite not working with PHP files!

Posted on 2006-06-16
4
553 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
  • 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

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…
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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