tags:

views:

230

answers:

5

My .htaccess file currently looks like this

AddType x-mapp-php5 .php
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^account$ /account/orders.php [L]

When I go to http://mywebsite.com/account it properly shows the page at http://mywebsite.com/account/orders.php. But when I change the RewriteRule to

RewriteRule ^account/orders$ /account/orders.php [L]

and then I go to http://mywebsite.com/account/orders, I get Error 404 Page Not Found. What did I do wrong?

**Additional Details**

I finally diagnosed the problem. But I don't understand why my solution works. Consider the scenario where account/orders.php exists.

The following rule will not work

RewriteRule ^account/orders$ account/orders.php [L]

The following rule will work

RewriteRule ^account/order$ account/orders.php [L]

Ie., the rewrite rule will fail if the Pattern evaluates to an existing file. So when the pattern is the same as the substitution, but minus the extension, the rewrite rule will fail. If I add a file called account/order.php, then both rules will fail.

Why does this happen?

A: 

Strange, it seems ok to me... If you have access to Apache Configuration try to enable RewriteLog and RewriteLogLevel for some debug...

Also take a look in the site's log files (always if you have access)

Alekc
sadly, I don't have access to apache configuration. My shared hosting provider says I don't have access to apache server logs. Are there other "types of logs" that I can check?
John
mmm i'm not pretty sure about this one, but maybe you can force an php script as default 404 page and do an print_r($_SERVER); inside it. In this mode you can see what exactly has been called and why apache doesn't find it.
Alekc
+1  A: 

I don't see how your first example would work, because I believe that intial slashes are also passed on.

RewriteRule ^/account/orders$ /account/orders.php [L]

jishi
A: 

Have you tried a relative path?

RewriteRule ^account/orders$ account/orders.php [L]


Edit   You should also make sure to have MultiViews disabled. This causes that Apache does some additional vague file matching to find similar named files and thus /account/orders would be mapped to /account/orders.php before it’s passed to mod_rewrite.

Gumbo
I have tried relatives paths and absolute paths for both terms of the rewriterule. Still the same problem
John
A: 

I would at first try to add a redirect to my rules, so I can see in the browser what is happening on the server.

RewriteRule ^account$ /account/orders.php [L,R]

Also make sure that there are no other rules (previous ones) interfering, just in case you are not showing all of your .htaccess file here.

Tomalak
yup, that's my entire .htaccess file, no other rules on it
John
RewriteRule ^account$ /account/orders.php [L,R] properly redirects, but the RewriteRule ^account/orders$ account/orders.php [L,R] redirects to a 404 page not found
John
A: 

I'm answering my own question because I finally diagnosed the problem. But I don't understand why my solution works. Consider the scenario where account/orders.php exists.

The following rule will not work

RewriteRule ^account/orders$ account/orders.php [L]

The following rule will work

RewriteRule ^account/order$ account/orders.php [L]

Ie., the rewrite rule will fail if the Pattern evaluates to an existing file. So when the pattern is the same as the substitution, but minus the extension, the rewrite rule will fail. If I add a file called account/order.php, then both rules will fail.

Why does this happen?

John