Maleka
Maleka

Reputation: 90

Simple .htaccess rewrite rule returning 'Not Found' issue

I have this code:

Options -Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^referral/([0-9]+)/?$ /referral.php?code=$1 [NC,L]

It is supposed to do two things:

Different formats have been tried, but the same error comes up:

Not Found

The requested URL /referral/[email protected] was not found on this server.

Apache/2.4.7 (Ubuntu) Server at Port 443

The first line of code works fine alone.

Upvotes: 1

Views: 635

Answers (2)

Maleka
Maleka

Reputation: 90

After viewing other related questions (notably this one), I finally got it to work by adding the following line:

Options -MultiViews

Upvotes: 1

MrWhite
MrWhite

Reputation: 45988

RewriteRule ^referral/([0-9]+)/?$ /referral.php?code=$1 [NC,L]

The RewriteRule pattern (ie. ^referral/([0-9]+)/?$) does not match a URL of the form "an address that ends with referral/[email protected]". For that you would need something like the following instead:

RewriteRule ^referral/([a-zA-Z0-9.@-]+)$ /referral.php?code=$1 [L]

This assumes that the URL "ends with" an email address, but that is otherwise the complete URL. The regex [0-9]+ only matches digits, not an email address (letters, digits, "@", ".", etc.), that you appear to require.

I've also removed the NC flag and incorporated the case-insensitivity into the regex, since I assume only the email address could be mixed case, not the URL-path?

Upvotes: 3

Related Questions