Solved

mod_rewrite not working with PHP files!

Posted on 2006-06-16
4
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now