dave sanchez
dave sanchez

Reputation: 45

.htaccess question - the [L] flag any way to simplify

I usually use MVC routing but I have to work on a site with non MVC and need to add a new feature.

Here is my commnads which works:

RewriteRule ^blog/why-am-using-htaccess/$ viewBlog.php?blogHook=$1 [L]
RewriteRule ^blog/(.*) blogs.php [L]
RewriteRule ^(.*)/$ page.php?hookName=$1

My issue is I have to put the [L] flag on everything above for it to work. I want to basically issue a flag to

RewriteRule ^(.*)/$ page.php?hookName=$1

That basically says do everything above but the last one is the fallback.

Is there any way to do that?

Upvotes: 0

Views: 34

Answers (1)

Natha
Natha

Reputation: 290

You have to use

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

before your last rule. The first rules rewrote the requested url to a valid (php) file which can be accessed, so the conditions will turn to false. If no rules matched before, but the requested url is a valid file yet (such as an image), this rule isn't processed too.

You should also omit the slash in the last rule: ^(.*)/$, because otherwise this rule only rewrites urls with an ending slash.

Upvotes: 1

Related Questions