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;








3















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?










share|improve this question



















  • 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

















3















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?










share|improve this question



















  • 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













3












3








3


4






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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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










3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer




















  • 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... 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


















3














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.






share|improve this answer
































    3














    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.






    share|improve this answer




















    • 1





      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











    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer




















    • 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... 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















    1














    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.






    share|improve this answer




















    • 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... 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













    1












    1








    1







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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... 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












    • 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... 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







    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













    3














    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.






    share|improve this answer





























      3














      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.






      share|improve this answer



























        3












        3








        3







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 30 '16 at 11:40

























        answered Sep 30 '16 at 11:30









        UnbelieverUnbeliever

        1,7311414




        1,7311414





















            3














            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.






            share|improve this answer




















            • 1





              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















            3














            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.






            share|improve this answer




















            • 1





              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













            3












            3








            3







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 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












            • 1





              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







            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

















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company