RewriteRule with trailing slash

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I need to redirect some link with or without trailing slashes:



www.domain.con/foo   → www.domain.com/redirect (working)
www.domain.com/foo/www.domain.com/redirect (not working)



I tried this rule in .htaccess:



RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]









share|improve this question




























    0















    I need to redirect some link with or without trailing slashes:



    www.domain.con/foo   → www.domain.com/redirect (working)
    www.domain.com/foo/www.domain.com/redirect (not working)



    I tried this rule in .htaccess:



    RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]









    share|improve this question


























      0












      0








      0








      I need to redirect some link with or without trailing slashes:



      www.domain.con/foo   → www.domain.com/redirect (working)
      www.domain.com/foo/www.domain.com/redirect (not working)



      I tried this rule in .htaccess:



      RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]









      share|improve this question
















      I need to redirect some link with or without trailing slashes:



      www.domain.con/foo   → www.domain.com/redirect (working)
      www.domain.com/foo/www.domain.com/redirect (not working)



      I tried this rule in .htaccess:



      RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]






      apache-httpd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 30 '14 at 21:21









      Gilles

      538k12810881605




      538k12810881605










      asked Sep 30 '14 at 9:14









      hellb0y77hellb0y77

      84162038




      84162038




















          2 Answers
          2






          active

          oldest

          votes


















          0














          To redirect www.domain.com/foo or www.domain.com/foo/ to www.domain.com/redirect you need to make the match on the trailing slash optional with a question mark (/?):



          RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]





          share|improve this answer























          • Same problem, don't work

            – hellb0y77
            Sep 30 '14 at 13:30











          • To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

            – hellb0y77
            Sep 30 '14 at 13:43












          • That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

            – garethTheRed
            Sep 30 '14 at 14:46











          • i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

            – hellb0y77
            Sep 30 '14 at 16:15











          • From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

            – garethTheRed
            Sep 30 '14 at 19:16


















          0














          RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]


          This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.






          share|improve this answer






















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f158380%2frewriterule-with-trailing-slash%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            To redirect www.domain.com/foo or www.domain.com/foo/ to www.domain.com/redirect you need to make the match on the trailing slash optional with a question mark (/?):



            RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]





            share|improve this answer























            • Same problem, don't work

              – hellb0y77
              Sep 30 '14 at 13:30











            • To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

              – hellb0y77
              Sep 30 '14 at 13:43












            • That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

              – garethTheRed
              Sep 30 '14 at 14:46











            • i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

              – hellb0y77
              Sep 30 '14 at 16:15











            • From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

              – garethTheRed
              Sep 30 '14 at 19:16















            0














            To redirect www.domain.com/foo or www.domain.com/foo/ to www.domain.com/redirect you need to make the match on the trailing slash optional with a question mark (/?):



            RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]





            share|improve this answer























            • Same problem, don't work

              – hellb0y77
              Sep 30 '14 at 13:30











            • To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

              – hellb0y77
              Sep 30 '14 at 13:43












            • That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

              – garethTheRed
              Sep 30 '14 at 14:46











            • i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

              – hellb0y77
              Sep 30 '14 at 16:15











            • From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

              – garethTheRed
              Sep 30 '14 at 19:16













            0












            0








            0







            To redirect www.domain.com/foo or www.domain.com/foo/ to www.domain.com/redirect you need to make the match on the trailing slash optional with a question mark (/?):



            RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]





            share|improve this answer













            To redirect www.domain.com/foo or www.domain.com/foo/ to www.domain.com/redirect you need to make the match on the trailing slash optional with a question mark (/?):



            RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 30 '14 at 11:42









            garethTheRedgarethTheRed

            24.5k36280




            24.5k36280












            • Same problem, don't work

              – hellb0y77
              Sep 30 '14 at 13:30











            • To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

              – hellb0y77
              Sep 30 '14 at 13:43












            • That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

              – garethTheRed
              Sep 30 '14 at 14:46











            • i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

              – hellb0y77
              Sep 30 '14 at 16:15











            • From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

              – garethTheRed
              Sep 30 '14 at 19:16

















            • Same problem, don't work

              – hellb0y77
              Sep 30 '14 at 13:30











            • To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

              – hellb0y77
              Sep 30 '14 at 13:43












            • That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

              – garethTheRed
              Sep 30 '14 at 14:46











            • i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

              – hellb0y77
              Sep 30 '14 at 16:15











            • From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

              – garethTheRed
              Sep 30 '14 at 19:16
















            Same problem, don't work

            – hellb0y77
            Sep 30 '14 at 13:30





            Same problem, don't work

            – hellb0y77
            Sep 30 '14 at 13:30













            To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

            – hellb0y77
            Sep 30 '14 at 13:43






            To resolve partially i have make a 301 redirect that work without trailing slash Redirect 301 /foo http://www.domain.com/redirect but with trailing slash and RewriteRule i have a double / es. http://www.domain.com/redirect//

            – hellb0y77
            Sep 30 '14 at 13:43














            That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

            – garethTheRed
            Sep 30 '14 at 14:46





            That's very odd. I've just ran a test on an Amazon EC2 instance and it does work. How are you testing? I used wget -O /dev/null --no-cache <url> to make sure that my browser wasn't caching anything. The above command will show the 301 redirect.

            – garethTheRed
            Sep 30 '14 at 14:46













            i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

            – hellb0y77
            Sep 30 '14 at 16:15





            i tried to move RewriteRule from .htaccess to /etc/httpd/conf.d/myconf.conf inside <Virtualhost> directive and my original rules works (RewriteRule (.*)/foo/$ http://www.domain.com/redirect$1 [L,R=301]). It's possible that RewriteRule works only in a vitrualhost directive?

            – hellb0y77
            Sep 30 '14 at 16:15













            From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

            – garethTheRed
            Sep 30 '14 at 19:16





            From the Apache documentation, RewriteRule works in server config, virtual host, directory, .htaccess

            – garethTheRed
            Sep 30 '14 at 19:16













            0














            RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]


            This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.






            share|improve this answer



























              0














              RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]


              This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.






              share|improve this answer

























                0












                0








                0







                RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]


                This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.






                share|improve this answer













                RewriteRule ^foo/?$ http://www.domain.com/redirect [L,R=301]


                This is a correct solution but will not carry the variable over, just a page to page. If you are having caching issues I recommend using https://httpstatus.io/ to verify the redirects as it doesn't seem to cache any of the redirect information. Also, testing using 302 instead of 301 will keep the browser from being stubborn about giving up the cached page location.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 8 '17 at 15:24









                Rich SRich S

                1




                1



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f158380%2frewriterule-with-trailing-slash%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

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay