Ben
Ben

Reputation: 9001

.htaccess mod_rewrite not consistent

Here is a sample from my .htaccess file:

RewriteEngine On

RewriteRule ^login/?$           loginregister.php [L]
RewriteRule ^register/?$        loginregister.php [L]
RewriteRule ^member/([^/]*)$    member.php?id=$1 [L]
RewriteRule ^members/?$         members.php [L]
RewriteRule ^membership/?$      membership.php [L]
RewriteRule ^contact/?$         contact.php [L]
RewriteRule ^privacy/?$         privacy.php [L]
RewriteRule ^terms/?$           terms.php [L]

If I visit example.com/login, it loads example.com/loginregister.php.

The same works for member/, members/, membership/ and contact/.

However, I have just added the rules for privacy/ and terms/, and they are not working.

When visiting those two pages I see this error:

Not Found

The requested URL /privacy was not found on this server.
Apache/2.4.10 (Unix) Server at example.com Port 80

However, if I access them directly (/privacy.php or /terms.php), they load fine.

Why are those two rules not working?

Upvotes: 1

Views: 86

Answers (2)

Rikesh
Rikesh

Reputation: 26431

As mention in my comment, it will work if you shuffle your rules from bottom to top. Possible reason could be conflicting rules. So your .htaccess should look like,

RewriteEngine On

RewriteRule ^privacy/?$         privacy.php [L]
RewriteRule ^terms/?$           terms.php [L]
RewriteRule ^login/?$           loginregister.php [L]
RewriteRule ^register/?$        loginregister.php [L]
RewriteRule ^member/([^/]*)$    member.php?id=$1 [L]
RewriteRule ^members/?$         members.php [L]
RewriteRule ^membership/?$      membership.php [L]
RewriteRule ^contact/?$         contact.php [L]

Upvotes: 2

nilsree
nilsree

Reputation: 302

If you don't have RewriteBase, try adding "RewriteBase /" or "RewriteBase /your/rewrite/path" in your .htaccess file.

This help the webserver to know where to look for the file, and some times solves this kind of strange behavior.

Upvotes: 0

Related Questions