.htaccess how use %{REQUEST_URI} in an test?
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 ...
# The following regular expression in the <if> need to some how operate on %{REQUEST_URI}!
<If "%{REQUEST_URI} !~ m#^/app(?:_dev)?.php/controller/home(/[a-z0-9]+)1?/?$#">
# 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.
.htaccess if-statement url-redirection
add a comment |
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 ...
# The following regular expression in the <if> need to some how operate on %{REQUEST_URI}!
<If "%{REQUEST_URI} !~ m#^/app(?:_dev)?.php/controller/home(/[a-z0-9]+)1?/?$#">
# 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.
.htaccess if-statement url-redirection
add a comment |
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 ...
# The following regular expression in the <if> need to some how operate on %{REQUEST_URI}!
<If "%{REQUEST_URI} !~ m#^/app(?:_dev)?.php/controller/home(/[a-z0-9]+)1?/?$#">
# 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.
.htaccess if-statement url-redirection
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 ...
# The following regular expression in the <if> need to some how operate on %{REQUEST_URI}!
<If "%{REQUEST_URI} !~ m#^/app(?:_dev)?.php/controller/home(/[a-z0-9]+)1?/?$#">
# 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.
.htaccess if-statement url-redirection
.htaccess if-statement url-redirection
edited Nov 19 '18 at 19:55
Howard Brown
asked Nov 18 '18 at 22:06
Howard BrownHoward Brown
855
855
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365928%2fhtaccess-how-use-request-uri-in-an-if-regex-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365928%2fhtaccess-how-use-request-uri-in-an-if-regex-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown