How to remove characters from a redirected URL in .htaccess?
up vote
0
down vote
favorite
I recently noticed a minor problem in a .htaccess redirect that I can't find a fix for.
I'm redirecting thousands of links of the form
"example.com/tinc?key={mass of random characters, etc}"
and repointing them at:
"example.com/search.php"
The following .htaccess command works fine:
"RedirectMatch 301 ^/tinc.*$ example.com/search.php"
...except that I just realised what it actually does is send the user to
example.com/search.php?key={mass of random characters, etc}
I thought that the .htaccess script directed the user to the new specific URL, but it's actually just replacing the first part of the original URL with the new one.
Because search.php just responds with the valid response that it can't find a match to the string, it's not disastrous, but it's not pretty in the address bar and I'd like it to work properly just for my own satisfaction.
So - can anyone advise how redirect in a way that loses the random string of characters at end, please? Thanks!
regex .htaccess redirect
add a comment |
up vote
0
down vote
favorite
I recently noticed a minor problem in a .htaccess redirect that I can't find a fix for.
I'm redirecting thousands of links of the form
"example.com/tinc?key={mass of random characters, etc}"
and repointing them at:
"example.com/search.php"
The following .htaccess command works fine:
"RedirectMatch 301 ^/tinc.*$ example.com/search.php"
...except that I just realised what it actually does is send the user to
example.com/search.php?key={mass of random characters, etc}
I thought that the .htaccess script directed the user to the new specific URL, but it's actually just replacing the first part of the original URL with the new one.
Because search.php just responds with the valid response that it can't find a match to the string, it's not disastrous, but it's not pretty in the address bar and I'd like it to work properly just for my own satisfaction.
So - can anyone advise how redirect in a way that loses the random string of characters at end, please? Thanks!
regex .htaccess redirect
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I recently noticed a minor problem in a .htaccess redirect that I can't find a fix for.
I'm redirecting thousands of links of the form
"example.com/tinc?key={mass of random characters, etc}"
and repointing them at:
"example.com/search.php"
The following .htaccess command works fine:
"RedirectMatch 301 ^/tinc.*$ example.com/search.php"
...except that I just realised what it actually does is send the user to
example.com/search.php?key={mass of random characters, etc}
I thought that the .htaccess script directed the user to the new specific URL, but it's actually just replacing the first part of the original URL with the new one.
Because search.php just responds with the valid response that it can't find a match to the string, it's not disastrous, but it's not pretty in the address bar and I'd like it to work properly just for my own satisfaction.
So - can anyone advise how redirect in a way that loses the random string of characters at end, please? Thanks!
regex .htaccess redirect
I recently noticed a minor problem in a .htaccess redirect that I can't find a fix for.
I'm redirecting thousands of links of the form
"example.com/tinc?key={mass of random characters, etc}"
and repointing them at:
"example.com/search.php"
The following .htaccess command works fine:
"RedirectMatch 301 ^/tinc.*$ example.com/search.php"
...except that I just realised what it actually does is send the user to
example.com/search.php?key={mass of random characters, etc}
I thought that the .htaccess script directed the user to the new specific URL, but it's actually just replacing the first part of the original URL with the new one.
Because search.php just responds with the valid response that it can't find a match to the string, it's not disastrous, but it's not pretty in the address bar and I'd like it to work properly just for my own satisfaction.
So - can anyone advise how redirect in a way that loses the random string of characters at end, please? Thanks!
regex .htaccess redirect
regex .htaccess redirect
edited Nov 12 at 11:55
asked Nov 10 at 22:51
Gavin W
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I can't see where the problem is, but being more explicit, and defining multiple rules might help:
RedirectMatch 301 ^example.com/tinc$ example.com/search.php
RedirectMatch 301 ^example.com/tinc?key=.*$ example.com/search.php
If that doesn't work, then assuming that your only GET parameter is key
, you could try this RewriteCond
.
RewriteCond %{QUERY_STRING} ^key=.*$
RewriteRule ^example.com/tinc$ example.com/search.php [L,R=301]
Good luck!
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I can't see where the problem is, but being more explicit, and defining multiple rules might help:
RedirectMatch 301 ^example.com/tinc$ example.com/search.php
RedirectMatch 301 ^example.com/tinc?key=.*$ example.com/search.php
If that doesn't work, then assuming that your only GET parameter is key
, you could try this RewriteCond
.
RewriteCond %{QUERY_STRING} ^key=.*$
RewriteRule ^example.com/tinc$ example.com/search.php [L,R=301]
Good luck!
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
add a comment |
up vote
0
down vote
I can't see where the problem is, but being more explicit, and defining multiple rules might help:
RedirectMatch 301 ^example.com/tinc$ example.com/search.php
RedirectMatch 301 ^example.com/tinc?key=.*$ example.com/search.php
If that doesn't work, then assuming that your only GET parameter is key
, you could try this RewriteCond
.
RewriteCond %{QUERY_STRING} ^key=.*$
RewriteRule ^example.com/tinc$ example.com/search.php [L,R=301]
Good luck!
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
add a comment |
up vote
0
down vote
up vote
0
down vote
I can't see where the problem is, but being more explicit, and defining multiple rules might help:
RedirectMatch 301 ^example.com/tinc$ example.com/search.php
RedirectMatch 301 ^example.com/tinc?key=.*$ example.com/search.php
If that doesn't work, then assuming that your only GET parameter is key
, you could try this RewriteCond
.
RewriteCond %{QUERY_STRING} ^key=.*$
RewriteRule ^example.com/tinc$ example.com/search.php [L,R=301]
Good luck!
I can't see where the problem is, but being more explicit, and defining multiple rules might help:
RedirectMatch 301 ^example.com/tinc$ example.com/search.php
RedirectMatch 301 ^example.com/tinc?key=.*$ example.com/search.php
If that doesn't work, then assuming that your only GET parameter is key
, you could try this RewriteCond
.
RewriteCond %{QUERY_STRING} ^key=.*$
RewriteRule ^example.com/tinc$ example.com/search.php [L,R=301]
Good luck!
answered Nov 14 at 2:06
Addison
1,4761734
1,4761734
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
add a comment |
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Thanks Addison, much appreciated, and at least I don't feel like I've missed something obvious now! Unfortunately, they result in the same problem; the string of characters persists in the form .../search.php?={original string}. As I say, it's as if the rules are simply resulting in replacement of everything up to the searched text, and leaving everything else in place. Thanks anyway!
– Gavin W
Nov 14 at 17:40
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
Do you think maybe something is happening to the URL after the replacement occurs? It's not normal that this is happening.
– Addison
Nov 14 at 23:30
1
1
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
I don't really know - I tried different strings and had the same result....until just now. I made up a link that should have failed and found that it now works as intended. The problem seems to lie in not trapping the "?" symbol. If I try "miramodus.com/tinc_add_any_string" it works as intended, if I try "miramodus.com/tinc?_add_any_string" it includes _add_any_string to the URL. Not clear why it does this, but trapping the ? mark in .htaccess should fix things. Many thanks for your help - you've inadvertently solved this for me!
– Gavin W
Nov 15 at 10:55
add a comment |
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%2f53244200%2fhow-to-remove-characters-from-a-redirected-url-in-htaccess%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