Apache RewriteMap with URLs containing space doesn't workApache mod_rewrite doesn't workRedirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Askhow to rewrite '%25' in urlRedirect apache to http requests to https except for when request is a POST?Redirect to absolute URL in .htaccess returns wrong host name on OpenShiftBest way configure 301 redirect forcing https:// no-www on a Serverpilot (nginx/apache server)CodeIgniter nginx rewrite rules for i8ln URL'sApache RewriteRule on VirtualHosts doesn't work with group capture regexApache redirect doesn't work on one specific subdomainMixing DBM Rewrite and Redirect how to stop Rewrite if url is not in list
How to write a 12-bar blues melody
Should homeowners insurance cover the cost of the home?
How to use dependency injection and avoid temporal coupling?
Word meaning as function of the composition of its phonemes
Has a commercial or military jet bi-plane ever been manufactured?
Adjacent DEM color matching in QGIS
Can you Ready a Bard spell to release it after using Battle Magic?
Do I add my skill check modifier to the roll of 15 granted by Glibness?
When two pilots are required for a private aircraft, is it a requirement for the PIC to be ATPL?
How can I get a job without pushing my family's income into a higher tax bracket?
Why aren't nationalizations in Russia described as socialist?
ZSPL language, anyone heard of it?
SafeCracker #3 - We've Been Blocked
Identifying characters
What to use instead of cling film to wrap pastry
How can I get people to remember my character's gender?
Nominativ or Akkusativ
Decoupling cap routing on a 4 layer PCB
Did we get closer to another plane than we were supposed to, or was the pilot just protecting our delicate sensibilities?
Would glacier 'trees' be plausible?
How long would it take for people to notice a mass disappearance?
Wrong answer from DSolve when solving a differential equation
Why wasn't the Night King naked in S08E03?
PWM 1Hz on solid state relay
Apache RewriteMap with URLs containing space doesn't work
Apache mod_rewrite doesn't workRedirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Askhow to rewrite '%25' in urlRedirect apache to http requests to https except for when request is a POST?Redirect to absolute URL in .htaccess returns wrong host name on OpenShiftBest way configure 301 redirect forcing https:// no-www on a Serverpilot (nginx/apache server)CodeIgniter nginx rewrite rules for i8ln URL'sApache RewriteRule on VirtualHosts doesn't work with group capture regexApache redirect doesn't work on one specific subdomainMixing DBM Rewrite and Redirect how to stop Rewrite if url is not in list
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am actually using a RewriteMap
directive inside my vhost to redirect a list of 800 URLs. It works quiet well:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$1 !=""
RewriteRule ^(.*)$ $redirects:$1 [redirect=permanent,last]
I use a redirect.txt
file containing the mapping. Then it is converted to a db file:
httxt2dbm -f db -i /data/apps/project/current/configuration/etc/httpd/conf/redirects.txt -o /data/apps/project/current/configuration/etc/httpd/conf/redirects.db
For example for this kind of URL, it is OK:
/associations/old_index.php /
But when the URL contains spaces it doesn't work: (I suppose it will be the same with other special characters)
/Universités%20direct /
How to handle this case?
virtualhost mod-rewrite redirect apache2
add a comment |
I am actually using a RewriteMap
directive inside my vhost to redirect a list of 800 URLs. It works quiet well:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$1 !=""
RewriteRule ^(.*)$ $redirects:$1 [redirect=permanent,last]
I use a redirect.txt
file containing the mapping. Then it is converted to a db file:
httxt2dbm -f db -i /data/apps/project/current/configuration/etc/httpd/conf/redirects.txt -o /data/apps/project/current/configuration/etc/httpd/conf/redirects.db
For example for this kind of URL, it is OK:
/associations/old_index.php /
But when the URL contains spaces it doesn't work: (I suppose it will be the same with other special characters)
/Universités%20direct /
How to handle this case?
virtualhost mod-rewrite redirect apache2
1
try/Universités direct
– Iain
Sep 29 '16 at 13:31
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
The URL-path matched by theRewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie."/Universités direct" /
?
– MrWhite
Sep 29 '16 at 13:49
Same result with the quotes.
– COil
Sep 29 '16 at 16:10
add a comment |
I am actually using a RewriteMap
directive inside my vhost to redirect a list of 800 URLs. It works quiet well:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$1 !=""
RewriteRule ^(.*)$ $redirects:$1 [redirect=permanent,last]
I use a redirect.txt
file containing the mapping. Then it is converted to a db file:
httxt2dbm -f db -i /data/apps/project/current/configuration/etc/httpd/conf/redirects.txt -o /data/apps/project/current/configuration/etc/httpd/conf/redirects.db
For example for this kind of URL, it is OK:
/associations/old_index.php /
But when the URL contains spaces it doesn't work: (I suppose it will be the same with other special characters)
/Universités%20direct /
How to handle this case?
virtualhost mod-rewrite redirect apache2
I am actually using a RewriteMap
directive inside my vhost to redirect a list of 800 URLs. It works quiet well:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$1 !=""
RewriteRule ^(.*)$ $redirects:$1 [redirect=permanent,last]
I use a redirect.txt
file containing the mapping. Then it is converted to a db file:
httxt2dbm -f db -i /data/apps/project/current/configuration/etc/httpd/conf/redirects.txt -o /data/apps/project/current/configuration/etc/httpd/conf/redirects.db
For example for this kind of URL, it is OK:
/associations/old_index.php /
But when the URL contains spaces it doesn't work: (I suppose it will be the same with other special characters)
/Universités%20direct /
How to handle this case?
virtualhost mod-rewrite redirect apache2
virtualhost mod-rewrite redirect apache2
edited Sep 29 '16 at 13:42
COil
asked Sep 29 '16 at 13:26
COilCOil
12211
12211
1
try/Universités direct
– Iain
Sep 29 '16 at 13:31
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
The URL-path matched by theRewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie."/Universités direct" /
?
– MrWhite
Sep 29 '16 at 13:49
Same result with the quotes.
– COil
Sep 29 '16 at 16:10
add a comment |
1
try/Universités direct
– Iain
Sep 29 '16 at 13:31
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
The URL-path matched by theRewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie."/Universités direct" /
?
– MrWhite
Sep 29 '16 at 13:49
Same result with the quotes.
– COil
Sep 29 '16 at 16:10
1
1
try
/Universités direct
– Iain
Sep 29 '16 at 13:31
try
/Universités direct
– Iain
Sep 29 '16 at 13:31
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
The URL-path matched by the
RewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie. "/Universités direct" /
?– MrWhite
Sep 29 '16 at 13:49
The URL-path matched by the
RewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie. "/Universités direct" /
?– MrWhite
Sep 29 '16 at 13:49
Same result with the quotes.
– COil
Sep 29 '16 at 16:10
Same result with the quotes.
– COil
Sep 29 '16 at 16:10
add a comment |
3 Answers
3
active
oldest
votes
A workaround might be to internally rewrite URLs that contain a space to a hyphen (replace the space with a hyphen) and include the hyphenated URL in your rewrite map instead.
If you only have some URLs that contain a single space within the URL then you could use something like the following directive before your existing directives:
RewriteRule ^(.+)s(.+)$ $1-$2
And then use the following in your rewrite map:
/Universités-direct /
UPDATE: If you have URLs that contain two spaces (eg. /the force awakens
) and some with one space then you could add an additional rule:
RewriteRule ^(.+)s(.+)s(.+)$ $1-$2
RewriteRule ^(.+)s(.+)$ $1-$2
These rules do assume that you don't have URLs that end with a space. And no URL has more than one contiguous space.
If three spaces then add another rule before the above...
RewriteRule ^(.+)s(.+)s(.+)s(.+)$ $1-$2
I would tend to do it this with multiple (simple) rules, rather than a generic "convert everything in a single rule", unless you specifically need that. A generic rule will run recursively, reducing multiple spaces to a single character. You will also likely need additional flags (ie. DPI
) to prevent a known rewrite bug in Apache.
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The%20
above doesn't seem to make sense in that context... theRewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class%20
will match the literal characters%
,2
and0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)
– MrWhite
Sep 30 '16 at 11:20
add a comment |
You can solve this by extracting the encoded URI from the %THE_REQUEST variable and using that to do the lookup. You need to put the encoded URIs in the map though of course. Something like the following:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond %THE_REQUEST "w+ ([^ ]+)"
RewriteRule ^ - [E=MYVAR:%1]
RewriteCond $redirects:%ENV:MYVAR !=""
RewriteRule ^ $redirects:%ENV:MYVAR [redirect=permanent,last] [B]
I've only tested it with a text based map instead of the DB one though. This will probably need modification if you have to deal with URLs with query strings.
add a comment |
You can use a second rewrite map, the internal function 'escape' this turns spaces into %20:
RewriteMap ec int:escape
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$ec:$1 !=""
RewriteRule ^(.*)$ $redirects:$ec:$1 [redirect=permanent,last]
Then in your own rewrite map db you can have:
/Universités-direct%20/
This should then match.
1
Interesting, didn't know about thisescape
function. I'll give a try. thanks.
– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
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%2fserverfault.com%2fquestions%2f806103%2fapache-rewritemap-with-urls-containing-space-doesnt-work%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
A workaround might be to internally rewrite URLs that contain a space to a hyphen (replace the space with a hyphen) and include the hyphenated URL in your rewrite map instead.
If you only have some URLs that contain a single space within the URL then you could use something like the following directive before your existing directives:
RewriteRule ^(.+)s(.+)$ $1-$2
And then use the following in your rewrite map:
/Universités-direct /
UPDATE: If you have URLs that contain two spaces (eg. /the force awakens
) and some with one space then you could add an additional rule:
RewriteRule ^(.+)s(.+)s(.+)$ $1-$2
RewriteRule ^(.+)s(.+)$ $1-$2
These rules do assume that you don't have URLs that end with a space. And no URL has more than one contiguous space.
If three spaces then add another rule before the above...
RewriteRule ^(.+)s(.+)s(.+)s(.+)$ $1-$2
I would tend to do it this with multiple (simple) rules, rather than a generic "convert everything in a single rule", unless you specifically need that. A generic rule will run recursively, reducing multiple spaces to a single character. You will also likely need additional flags (ie. DPI
) to prevent a known rewrite bug in Apache.
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The%20
above doesn't seem to make sense in that context... theRewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class%20
will match the literal characters%
,2
and0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)
– MrWhite
Sep 30 '16 at 11:20
add a comment |
A workaround might be to internally rewrite URLs that contain a space to a hyphen (replace the space with a hyphen) and include the hyphenated URL in your rewrite map instead.
If you only have some URLs that contain a single space within the URL then you could use something like the following directive before your existing directives:
RewriteRule ^(.+)s(.+)$ $1-$2
And then use the following in your rewrite map:
/Universités-direct /
UPDATE: If you have URLs that contain two spaces (eg. /the force awakens
) and some with one space then you could add an additional rule:
RewriteRule ^(.+)s(.+)s(.+)$ $1-$2
RewriteRule ^(.+)s(.+)$ $1-$2
These rules do assume that you don't have URLs that end with a space. And no URL has more than one contiguous space.
If three spaces then add another rule before the above...
RewriteRule ^(.+)s(.+)s(.+)s(.+)$ $1-$2
I would tend to do it this with multiple (simple) rules, rather than a generic "convert everything in a single rule", unless you specifically need that. A generic rule will run recursively, reducing multiple spaces to a single character. You will also likely need additional flags (ie. DPI
) to prevent a known rewrite bug in Apache.
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The%20
above doesn't seem to make sense in that context... theRewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class%20
will match the literal characters%
,2
and0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)
– MrWhite
Sep 30 '16 at 11:20
add a comment |
A workaround might be to internally rewrite URLs that contain a space to a hyphen (replace the space with a hyphen) and include the hyphenated URL in your rewrite map instead.
If you only have some URLs that contain a single space within the URL then you could use something like the following directive before your existing directives:
RewriteRule ^(.+)s(.+)$ $1-$2
And then use the following in your rewrite map:
/Universités-direct /
UPDATE: If you have URLs that contain two spaces (eg. /the force awakens
) and some with one space then you could add an additional rule:
RewriteRule ^(.+)s(.+)s(.+)$ $1-$2
RewriteRule ^(.+)s(.+)$ $1-$2
These rules do assume that you don't have URLs that end with a space. And no URL has more than one contiguous space.
If three spaces then add another rule before the above...
RewriteRule ^(.+)s(.+)s(.+)s(.+)$ $1-$2
I would tend to do it this with multiple (simple) rules, rather than a generic "convert everything in a single rule", unless you specifically need that. A generic rule will run recursively, reducing multiple spaces to a single character. You will also likely need additional flags (ie. DPI
) to prevent a known rewrite bug in Apache.
A workaround might be to internally rewrite URLs that contain a space to a hyphen (replace the space with a hyphen) and include the hyphenated URL in your rewrite map instead.
If you only have some URLs that contain a single space within the URL then you could use something like the following directive before your existing directives:
RewriteRule ^(.+)s(.+)$ $1-$2
And then use the following in your rewrite map:
/Universités-direct /
UPDATE: If you have URLs that contain two spaces (eg. /the force awakens
) and some with one space then you could add an additional rule:
RewriteRule ^(.+)s(.+)s(.+)$ $1-$2
RewriteRule ^(.+)s(.+)$ $1-$2
These rules do assume that you don't have URLs that end with a space. And no URL has more than one contiguous space.
If three spaces then add another rule before the above...
RewriteRule ^(.+)s(.+)s(.+)s(.+)$ $1-$2
I would tend to do it this with multiple (simple) rules, rather than a generic "convert everything in a single rule", unless you specifically need that. A generic rule will run recursively, reducing multiple spaces to a single character. You will also likely need additional flags (ie. DPI
) to prevent a known rewrite bug in Apache.
edited Sep 30 '16 at 11:18
answered Sep 29 '16 at 21:51
MrWhiteMrWhite
6,46921426
6,46921426
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The%20
above doesn't seem to make sense in that context... theRewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class%20
will match the literal characters%
,2
and0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)
– MrWhite
Sep 30 '16 at 11:20
add a comment |
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The%20
above doesn't seem to make sense in that context... theRewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class%20
will match the literal characters%
,2
and0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)
– MrWhite
Sep 30 '16 at 11:20
1
1
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
We are near. It works but only when there is only one space in the URL. The regexp (.+)s(.+) must be tuned. Thanks.
– COil
Sep 30 '16 at 8:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:
RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
In this post there is the clue: stackoverflow.com/questions/5821120/… but I can't make it work:
RewriteRule ^([^s%20]*)[s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
– COil
Sep 30 '16 at 9:39
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The
%20
above doesn't seem to make sense in that context... the RewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class %20
will match the literal characters %
, 2
and 0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)– MrWhite
Sep 30 '16 at 11:20
Do you need a general solution that converts all spaces? Otherwise, I would keep it specific to your situation. The
%20
above doesn't seem to make sense in that context... the RewriteRule
pattern matches the %-decoded URL anyway, but when used in a character class %20
will match the literal characters %
, 2
and 0
- which is not desirable. Also note that these general solutions will reduce multiple contiguous spaces to a single char. (I've updated my answer to handle two or three spaces.)– MrWhite
Sep 30 '16 at 11:20
add a comment |
You can solve this by extracting the encoded URI from the %THE_REQUEST variable and using that to do the lookup. You need to put the encoded URIs in the map though of course. Something like the following:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond %THE_REQUEST "w+ ([^ ]+)"
RewriteRule ^ - [E=MYVAR:%1]
RewriteCond $redirects:%ENV:MYVAR !=""
RewriteRule ^ $redirects:%ENV:MYVAR [redirect=permanent,last] [B]
I've only tested it with a text based map instead of the DB one though. This will probably need modification if you have to deal with URLs with query strings.
add a comment |
You can solve this by extracting the encoded URI from the %THE_REQUEST variable and using that to do the lookup. You need to put the encoded URIs in the map though of course. Something like the following:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond %THE_REQUEST "w+ ([^ ]+)"
RewriteRule ^ - [E=MYVAR:%1]
RewriteCond $redirects:%ENV:MYVAR !=""
RewriteRule ^ $redirects:%ENV:MYVAR [redirect=permanent,last] [B]
I've only tested it with a text based map instead of the DB one though. This will probably need modification if you have to deal with URLs with query strings.
add a comment |
You can solve this by extracting the encoded URI from the %THE_REQUEST variable and using that to do the lookup. You need to put the encoded URIs in the map though of course. Something like the following:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond %THE_REQUEST "w+ ([^ ]+)"
RewriteRule ^ - [E=MYVAR:%1]
RewriteCond $redirects:%ENV:MYVAR !=""
RewriteRule ^ $redirects:%ENV:MYVAR [redirect=permanent,last] [B]
I've only tested it with a text based map instead of the DB one though. This will probably need modification if you have to deal with URLs with query strings.
You can solve this by extracting the encoded URI from the %THE_REQUEST variable and using that to do the lookup. You need to put the encoded URIs in the map though of course. Something like the following:
RewriteEngine On
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond %THE_REQUEST "w+ ([^ ]+)"
RewriteRule ^ - [E=MYVAR:%1]
RewriteCond $redirects:%ENV:MYVAR !=""
RewriteRule ^ $redirects:%ENV:MYVAR [redirect=permanent,last] [B]
I've only tested it with a text based map instead of the DB one though. This will probably need modification if you have to deal with URLs with query strings.
edited Sep 30 '16 at 11:40
answered Sep 30 '16 at 11:30
UnbelieverUnbeliever
1,7311414
1,7311414
add a comment |
add a comment |
You can use a second rewrite map, the internal function 'escape' this turns spaces into %20:
RewriteMap ec int:escape
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$ec:$1 !=""
RewriteRule ^(.*)$ $redirects:$ec:$1 [redirect=permanent,last]
Then in your own rewrite map db you can have:
/Universités-direct%20/
This should then match.
1
Interesting, didn't know about thisescape
function. I'll give a try. thanks.
– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
add a comment |
You can use a second rewrite map, the internal function 'escape' this turns spaces into %20:
RewriteMap ec int:escape
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$ec:$1 !=""
RewriteRule ^(.*)$ $redirects:$ec:$1 [redirect=permanent,last]
Then in your own rewrite map db you can have:
/Universités-direct%20/
This should then match.
1
Interesting, didn't know about thisescape
function. I'll give a try. thanks.
– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
add a comment |
You can use a second rewrite map, the internal function 'escape' this turns spaces into %20:
RewriteMap ec int:escape
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$ec:$1 !=""
RewriteRule ^(.*)$ $redirects:$ec:$1 [redirect=permanent,last]
Then in your own rewrite map db you can have:
/Universités-direct%20/
This should then match.
You can use a second rewrite map, the internal function 'escape' this turns spaces into %20:
RewriteMap ec int:escape
RewriteMap redirects dbm=db:/data/apps/project/current/configuration/etc/httpd/conf/redirects.db
RewriteCond $redirects:$ec:$1 !=""
RewriteRule ^(.*)$ $redirects:$ec:$1 [redirect=permanent,last]
Then in your own rewrite map db you can have:
/Universités-direct%20/
This should then match.
edited Jan 4 '18 at 13:41
Dave M
4,37982428
4,37982428
answered Jan 4 '18 at 11:08
Chris LawtonChris Lawton
312
312
1
Interesting, didn't know about thisescape
function. I'll give a try. thanks.
– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
add a comment |
1
Interesting, didn't know about thisescape
function. I'll give a try. thanks.
– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
1
1
Interesting, didn't know about this
escape
function. I'll give a try. thanks.– COil
Jan 4 '18 at 11:27
Interesting, didn't know about this
escape
function. I'll give a try. thanks.– COil
Jan 4 '18 at 11:27
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
imho this is the best answer. Way more robust than the other answers and minimal changes (just insert the escape map at the right position) if you already have your rules setup to work with urls without special characters.
– Tom Cannaerts
Jun 26 '18 at 11:08
add a comment |
Thanks for contributing an answer to Server Fault!
- 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%2fserverfault.com%2fquestions%2f806103%2fapache-rewritemap-with-urls-containing-space-doesnt-work%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
1
try
/Universités direct
– Iain
Sep 29 '16 at 13:31
@w3dk a RewriteMap indeed, fixed.
– COil
Sep 29 '16 at 13:42
@Hanginoninquietdesperation Doesn't work, remember that the redirect is itself in the db file not in the vhost.
– COil
Sep 29 '16 at 13:46
The URL-path matched by the
RewriteRule
pattern is %-decoded, so @Hanginoninquietdesperation is certainly on the right track I would say. Try surrounding the value in double quotes. ie."/Universités direct" /
?– MrWhite
Sep 29 '16 at 13:49
Same result with the quotes.
– COil
Sep 29 '16 at 16:10