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

            Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

            Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

            Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020