Solved

mod_rewrite not working with PHP files!

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

10 Experts available now in Live!

Get 1:1 Help Now