Neville
Neville

Reputation: 528

HTACCESS resulting in error 404

I have the following htaccess codes in a subdirectory

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L]

It works fine. The problem is every other page in that directory gives an error 404.

The link example.com/sub/sub/123456.html works fine. Also, example.com/sub/sub/ works fine since I have an index file in the sub directory. However, example.com/sub/sub/anotherpage.html gives error 404. Deleting the htaccess solves one problem and brings the other.

example.com/sub/sub/

Upvotes: 3

Views: 192

Answers (3)

Neville
Neville

Reputation: 528

Works now. It looks like I had to remove the .php extension in the htaccess in sub/sub/ too.

Upvotes: 0

Dekel
Dekel

Reputation: 62666

You can add

RewriteCond %{REQUEST_FILENAME} !-f

To your code to make sure to ignore files that exists in your folder.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L]

Upvotes: 1

Georges O.
Georges O.

Reputation: 992

You tried to access to page with alphanumeric name. But, on your htaccess it's only for numeric ones.

RewriteRule ^([0-9]+).html$ order-details.php?id=$1 [NC,L] Access only numerical names due to [0-9]

If you want to redirect alphanumerical, you have to use another mask. Maybe [0-9A-Za-z] ?

Upvotes: 0

Related Questions