aardbol
aardbol

Reputation: 2295

mod rewrite issue

How come this one works:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/book/blabla$
RewriteRule ^.+$ /book/?name=blabla [NC,L]

But this one doesn't?

RewriteEngine On

RewriteRule ^/book/blabla$ /book/?name=blabla [NC,L]

I've tried many things but it's confusing me.

Upvotes: 2

Views: 56

Answers (1)

Gumbo
Gumbo

Reputation: 655129

If you’re using mod_rewrite in a .htaccess file, the contextual per-directory prefix of the URL path is removed before testing the rules:

As you will see below, RewriteRule can be used in per-directory config files (.htaccess). In such a case, it will act locally, stripping the local directory prefix before processing, and applying rewrite rules only to the remainder.

That means if you use mod_rewrite in the .htaccess file in the root directory (/), that path prefix is removed from the URL path. So /book/blabla is reduced to book/blabla. Your rule pattern must reflect that behavior:

RewriteRule ^book/blabla$ /book/?name=blabla [NC,L]

Upvotes: 2

Related Questions