uguMark
uguMark

Reputation: 611

Need to override previously written rewrite rule

I have some rewrite rules in an htaccess file. I'm still getting into it so theres a few things I'm unsure of. Basically I want all pages (except the /register page) to be rewritten like this: http://www.example.com/about -> http://www.example.com?page=about

To get that right I wrote this rule:

RewriteRule ^([a-z-_1-9]+)+/?$ ./?page=$1&%{QUERY_STRING} [L]

I then wrote this rule below the one above thinking it would override it, but it doesnt...

RewriteRule ^register/?$ ./?page=login&option=register

So going to /register gives me a 404. However if I comment out the first rule then the register page works. I was thinking it would work like CSS where writing a new rule below would take precedence. How would I get this right and how do you override previously written rewrite rules?

Thanks!

Upvotes: 0

Views: 2113

Answers (1)

LazyOne
LazyOne

Reputation: 165198

.htaccess is not CSS -- especially when it comes to mod_rewrite instructions/rules.

The rules are executed from top to bottom. Therefore -- put more specific rules at top and then more generic at bottom.

In your case:

RewriteRule ^register/?$ ./?page=login&option=register [L]
RewriteRule ^([a-z-_1-9]+)+/?$ ./?page=$1&%{QUERY_STRING} [L]

Upvotes: 2

Related Questions