dimanche 18 novembre 2018

.htaccess how use %{REQUEST_URI} in an

The Apache documentation on using <If expression> tests with regular expressions seems to say that you can do this with a %{variables}, such as %{REQUEST_URI}, but it doesn't show any examples of how to actually do this.

My .htaccess is suffering from a URL mod loop, where after successfully passing through the .htaccess and modifying the URL to a value I want, the 'engine' re-runs the .htaccess again, due to the redirection, but this time the resultant URL is now bad or non-existent. I've spent a lot of time trying to 'tighten' the RewriteCond/RewriteRule to prevent this, but not had much luck with that.

Is it possible to explicitly prevent the block of rewrites from being run when the incoming URL is valid for my site, possibly with an <If></If> statement?

# Prevent valid URL from being modified ...

<If %{REQUEST_URI} != m#^/app(?:_dev)?\.php/controller/home(/[a-z0-9]+)?/?$#>

    # RewriteCond/RewriteRule sets to modify the URL go here

</If>

# Other RewriteCond/RewriteRule sets used by Symfony2 go here.

I realize that the <If> shown in my code example isn't right, but I don't know how to 'inject' the %⁠{REQUEST_URI} into the regular expression.

I ask about <If></If> because it doesn't cause a redirection and can skip over an arbitrary number of RewriteCond/RewriteRule sets with in the statement block and yet allow other sets following the statement block to still run normally. While the RewriteCond/RewriteRule set's [S=###] flag seems to possibly allow this as well, it would cause another redirect and subsequent loop, plus, I would have to update the ### each time I changed the RewriteCond/RewriteRule sets that needed to be skipped.

Aucun commentaire:

Enregistrer un commentaire