.htaccess redirects aren't respecting my regex The Next CEO of Stack OverflowCheck to see if a key exists in a query string - htaccesshtaccess rewrite to include #!htaccess QUERY_STRING urldecodeAllow multiple IPs to access Wordpress Site Admin via .htaccesshtaccess redirect if index.php is missing301 htaccess redirect dynamic URL in a subfolder to home page.htaccess redirect with unique url AND query stringhtaccess query string redirect not workingMultiple languages + Htaccess404 issue in two htaccess in root domain and subfoler
What is the point of a new vote on May's deal when the indicative votes suggest she will not win?
Are there languages with no euphemisms?
How do I construct this japanese bowl?
How to be diplomatic in refusing to write code that breaches the privacy of our users
How to Reset Passwords on Multiple Websites Easily?
Why do professional authors make "consistency" mistakes? And how to avoid them?
Go Pregnant or Go Home
How do I go from 300 unfinished/half written blog posts, to published posts?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Why were Madagascar and New Zealand discovered so late?
Natural language into sentence logic
Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?
Opposite of a diet
Fastest way to shutdown Ubuntu Mate 18.10
Is it okay to store user locations?
How easy is it to start Magic from scratch?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
Why didn't Khan get resurrected in the Genesis Explosion?
How to count occurrences of text in a file?
How to make a software documentation "officially" citable?
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
Why did we only see the N-1 starfighters in one film?
Grabbing quick drinks
.htaccess redirects aren't respecting my regex
The Next CEO of Stack OverflowCheck to see if a key exists in a query string - htaccesshtaccess rewrite to include #!htaccess QUERY_STRING urldecodeAllow multiple IPs to access Wordpress Site Admin via .htaccesshtaccess redirect if index.php is missing301 htaccess redirect dynamic URL in a subfolder to home page.htaccess redirect with unique url AND query stringhtaccess query string redirect not workingMultiple languages + Htaccess404 issue in two htaccess in root domain and subfoler
I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.
For example, I need to redirect:http://example.com/test1/test2/[origin]/?id=1
back tohttp://example.com/thank-you
The way I've got it set up in my .htaccess file is as such:
RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you
I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.
Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.
My question is: the redirect works perfectly from the page without the query string if I remove the .+
from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.
I have also tried:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]
regex .htaccess query-string
add a comment |
I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.
For example, I need to redirect:http://example.com/test1/test2/[origin]/?id=1
back tohttp://example.com/thank-you
The way I've got it set up in my .htaccess file is as such:
RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you
I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.
Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.
My question is: the redirect works perfectly from the page without the query string if I remove the .+
from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.
I have also tried:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]
regex .htaccess query-string
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
1
Your second set of code (RewriteRule) could work with flags[R=302,L,QSD]
.
– AdminOfThings
Mar 21 at 18:50
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07
add a comment |
I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.
For example, I need to redirect:http://example.com/test1/test2/[origin]/?id=1
back tohttp://example.com/thank-you
The way I've got it set up in my .htaccess file is as such:
RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you
I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.
Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.
My question is: the redirect works perfectly from the page without the query string if I remove the .+
from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.
I have also tried:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]
regex .htaccess query-string
I need to redirect any requests with query strings from a set of origin URLs back to a thank you page.
For example, I need to redirect:http://example.com/test1/test2/[origin]/?id=1
back tohttp://example.com/thank-you
The way I've got it set up in my .htaccess file is as such:
RewriteEngine On
RedirectMatch 302 ^/test1/test2/(.*)/.+ /thank-you
I've tested the regex I'm using in an online regex tester and it appears to work as expected, so I'm confused as to why the redirect isn't taking place. Here's the link to that.
Obviously, I had to add backslashes to escape the slashes in the URL in the regex tester, but based on my understanding of how .htaccess evaluates regex, these aren't necessary.
My question is: the redirect works perfectly from the page without the query string if I remove the .+
from the end of the regex string, meaning that the beginning part of the regex works fine. I don't understand why the query string isn't matching the regex I've created.
I have also tried:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L]
regex .htaccess query-string
regex .htaccess query-string
edited Mar 21 at 17:17
IanCZane
asked Mar 21 at 16:36
IanCZaneIanCZane
12012
12012
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
1
Your second set of code (RewriteRule) could work with flags[R=302,L,QSD]
.
– AdminOfThings
Mar 21 at 18:50
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07
add a comment |
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
1
Your second set of code (RewriteRule) could work with flags[R=302,L,QSD]
.
– AdminOfThings
Mar 21 at 18:50
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
1
1
Your second set of code (RewriteRule) could work with flags
[R=302,L,QSD]
.– AdminOfThings
Mar 21 at 18:50
Your second set of code (RewriteRule) could work with flags
[R=302,L,QSD]
.– AdminOfThings
Mar 21 at 18:50
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07
add a comment |
2 Answers
2
active
oldest
votes
First , no need to RewriteEngine On
with mod_alias
which is RedirectMatch
at your rules use it with mod_rewrite
, the second rules .
Try this :
RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]
I use ^id=([0-9]+)$
to restrict query string for a one that start with id
and end with numerical value
.
I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
becasue you could match against URI in RewriteRule
as well.
If this rules wrok , change [R=302,L]
to [R=301,L]
to be permanent redirection.
Note: clear browser cache then test
add a comment |
For your RedirectMatch, you may use:
RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?
For your RewriteRule section, you may use:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L,QSD]
add a comment |
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%2f55285233%2fhtaccess-redirects-arent-respecting-my-regex%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
First , no need to RewriteEngine On
with mod_alias
which is RedirectMatch
at your rules use it with mod_rewrite
, the second rules .
Try this :
RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]
I use ^id=([0-9]+)$
to restrict query string for a one that start with id
and end with numerical value
.
I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
becasue you could match against URI in RewriteRule
as well.
If this rules wrok , change [R=302,L]
to [R=301,L]
to be permanent redirection.
Note: clear browser cache then test
add a comment |
First , no need to RewriteEngine On
with mod_alias
which is RedirectMatch
at your rules use it with mod_rewrite
, the second rules .
Try this :
RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]
I use ^id=([0-9]+)$
to restrict query string for a one that start with id
and end with numerical value
.
I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
becasue you could match against URI in RewriteRule
as well.
If this rules wrok , change [R=302,L]
to [R=301,L]
to be permanent redirection.
Note: clear browser cache then test
add a comment |
First , no need to RewriteEngine On
with mod_alias
which is RedirectMatch
at your rules use it with mod_rewrite
, the second rules .
Try this :
RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]
I use ^id=([0-9]+)$
to restrict query string for a one that start with id
and end with numerical value
.
I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
becasue you could match against URI in RewriteRule
as well.
If this rules wrok , change [R=302,L]
to [R=301,L]
to be permanent redirection.
Note: clear browser cache then test
First , no need to RewriteEngine On
with mod_alias
which is RedirectMatch
at your rules use it with mod_rewrite
, the second rules .
Try this :
RewriteEngine On
RewriteCond %QUERY_STRING ^id=([0-9]+)$ [NC]
RewriteRule ^test1/test2/[^/]+/$ /thank-you? [R=302,L]
I use ^id=([0-9]+)$
to restrict query string for a one that start with id
and end with numerical value
.
I remove this line RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
becasue you could match against URI in RewriteRule
as well.
If this rules wrok , change [R=302,L]
to [R=301,L]
to be permanent redirection.
Note: clear browser cache then test
answered Mar 21 at 20:07
Mohammed ElhagMohammed Elhag
3,9261516
3,9261516
add a comment |
add a comment |
For your RedirectMatch, you may use:
RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?
For your RewriteRule section, you may use:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L,QSD]
add a comment |
For your RedirectMatch, you may use:
RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?
For your RewriteRule section, you may use:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L,QSD]
add a comment |
For your RedirectMatch, you may use:
RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?
For your RewriteRule section, you may use:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L,QSD]
For your RedirectMatch, you may use:
RedirectMatch 302 ^/test1/test2/(.*)/(.*)+ /thank-you?
For your RewriteRule section, you may use:
RewriteCond %REQUEST_URI ^/test1/test2/(.*)/
RewriteCond %QUERY_STRING id=([0-9]+) [NC]
RewriteRule (.*) /thank-you [R=302,L,QSD]
edited Mar 21 at 20:30
answered Mar 21 at 19:14
AdminOfThingsAdminOfThings
1,5951212
1,5951212
add a comment |
add a comment |
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.
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%2f55285233%2fhtaccess-redirects-arent-respecting-my-regex%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
No, .htaccess doesn't use double quotes, it just uses unescaped spaces to separate arguments.
– IanCZane
Mar 21 at 17:16
1
Your second set of code (RewriteRule) could work with flags
[R=302,L,QSD]
.– AdminOfThings
Mar 21 at 18:50
@IanCZane your second rules , only add ? after target thank-you like this thank-you?
– Mohammed Elhag
Mar 21 at 19:07