Redirect anything within /attachments/ directory up one level but also removing anything after...

Function pointer with named arguments?

Critique of timeline aesthetic

Classification of surfaces

Do I have an "anti-research" personality?

Mistake in years of experience in resume?

Why do games have consumables?

What is the smallest unit of eos?

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

Map of water taps to fill bottles

Is it idiomatic to construct against `this`

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Can I grease a crank spindle/bracket without disassembling the crank set?

"The cow" OR "a cow" OR "cows" in this context

As an international instructor, should I openly talk about my accent?

What happened to Captain America in Endgame?

Two field separators (colon and space) in awk

Elements other than carbon that can form many different compounds by bonding to themselves?

Don’t seats that recline flat defeat the purpose of having seatbelts?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

How exactly does Hawking radiation decrease the mass of black holes?

How would 10 generations of living underground change the human body?

What does ゆーか mean?

Can I criticise the more senior developers around me for not writing clean code?

Could the terminal length of components like resistors be reduced?



Redirect anything within /attachments/ directory up one level but also removing anything after /attachments/


Cannot 301 redirect with IIS URL Rewrite ModuleHow do I obscure my Wordpress install via htaccess?How To Manually Redirect URLs To a New BlogApache + Codeigniter + New Server + Unexpected ErrorsRedirecting a single request to another pages, ignoring www subdomainEnable Cross Origin Scripting on Nginx from retina.js to load files from another URL?Permanently Redirect Subfolder Blog to Subdomain on Another ServerRedirect to absolute URL in .htaccess returns wrong host name on OpenShiftWordpress Permalinks and regular php filesCustom URL's Nginx & PHP






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















WordPress creates an attachment page for any images uploaded through the post editor and "attached" to that post. After migrating a site, those attachment pages no longer exist, and we now have around 1000 links pointed at 404's.



So, I was looking to find a way to do a redirect for any url that has /attachement/ in it's string and then push that url back up one level (which happens to be the post page). so for instance:



http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (which doesnt exist) will go to
http://mysite.com/2012/news/blog-post-title/ (which does exist).



Along with redirecting up one level, I also need to remove anything after /attachment/ (in this case the "image-page."



Any suggestions?



Thanks in advance










share|improve this question














bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    1















    WordPress creates an attachment page for any images uploaded through the post editor and "attached" to that post. After migrating a site, those attachment pages no longer exist, and we now have around 1000 links pointed at 404's.



    So, I was looking to find a way to do a redirect for any url that has /attachement/ in it's string and then push that url back up one level (which happens to be the post page). so for instance:



    http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (which doesnt exist) will go to
    http://mysite.com/2012/news/blog-post-title/ (which does exist).



    Along with redirecting up one level, I also need to remove anything after /attachment/ (in this case the "image-page."



    Any suggestions?



    Thanks in advance










    share|improve this question














    bumped to the homepage by Community 5 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1








      WordPress creates an attachment page for any images uploaded through the post editor and "attached" to that post. After migrating a site, those attachment pages no longer exist, and we now have around 1000 links pointed at 404's.



      So, I was looking to find a way to do a redirect for any url that has /attachement/ in it's string and then push that url back up one level (which happens to be the post page). so for instance:



      http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (which doesnt exist) will go to
      http://mysite.com/2012/news/blog-post-title/ (which does exist).



      Along with redirecting up one level, I also need to remove anything after /attachment/ (in this case the "image-page."



      Any suggestions?



      Thanks in advance










      share|improve this question














      WordPress creates an attachment page for any images uploaded through the post editor and "attached" to that post. After migrating a site, those attachment pages no longer exist, and we now have around 1000 links pointed at 404's.



      So, I was looking to find a way to do a redirect for any url that has /attachement/ in it's string and then push that url back up one level (which happens to be the post page). so for instance:



      http://mysite.com/2012/news/blog-post-title/attachment/image-page/ (which doesnt exist) will go to
      http://mysite.com/2012/news/blog-post-title/ (which does exist).



      Along with redirecting up one level, I also need to remove anything after /attachment/ (in this case the "image-page."



      Any suggestions?



      Thanks in advance







      .htaccess redirect






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 6 '12 at 22:53









      Rich StaatsRich Staats

      61




      61





      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 5 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This sounds like an extremely simple rewrite; unless there's something missing, you can use:



          RewriteRule ^(.*)/attachment/?.*$ $1/


          So some test cases:



          /2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachments -> N/A


          Hope this helps!






          share|improve this answer
























          • thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

            – Rich Staats
            Apr 9 '12 at 21:38











          • You can try turning on logging and seeing what actions its taking.

            – Andrew M.
            Apr 10 '12 at 5:21














          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%2f377431%2fredirect-anything-within-attachments-directory-up-one-level-but-also-removing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This sounds like an extremely simple rewrite; unless there's something missing, you can use:



          RewriteRule ^(.*)/attachment/?.*$ $1/


          So some test cases:



          /2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachments -> N/A


          Hope this helps!






          share|improve this answer
























          • thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

            – Rich Staats
            Apr 9 '12 at 21:38











          • You can try turning on logging and seeing what actions its taking.

            – Andrew M.
            Apr 10 '12 at 5:21


















          0














          This sounds like an extremely simple rewrite; unless there's something missing, you can use:



          RewriteRule ^(.*)/attachment/?.*$ $1/


          So some test cases:



          /2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachments -> N/A


          Hope this helps!






          share|improve this answer
























          • thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

            – Rich Staats
            Apr 9 '12 at 21:38











          • You can try turning on logging and seeing what actions its taking.

            – Andrew M.
            Apr 10 '12 at 5:21
















          0












          0








          0







          This sounds like an extremely simple rewrite; unless there's something missing, you can use:



          RewriteRule ^(.*)/attachment/?.*$ $1/


          So some test cases:



          /2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachments -> N/A


          Hope this helps!






          share|improve this answer













          This sounds like an extremely simple rewrite; unless there's something missing, you can use:



          RewriteRule ^(.*)/attachment/?.*$ $1/


          So some test cases:



          /2012/news/blog-post-title/attachment/image-page/ -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachment -> /2012/news/blog-post-title/
          /2012/news/blog-post-title/attachments -> N/A


          Hope this helps!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 7 '12 at 0:20









          Andrew M.Andrew M.

          9,73112927




          9,73112927













          • thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

            – Rich Staats
            Apr 9 '12 at 21:38











          • You can try turning on logging and seeing what actions its taking.

            – Andrew M.
            Apr 10 '12 at 5:21





















          • thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

            – Rich Staats
            Apr 9 '12 at 21:38











          • You can try turning on logging and seeing what actions its taking.

            – Andrew M.
            Apr 10 '12 at 5:21



















          thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

          – Rich Staats
          Apr 9 '12 at 21:38





          thanks for helping out. I added that bit of code to the .htaccess file but the redirects are not occuring. I checked to make sure that the RewriteEngine was On an functioning, and it was. How would you suggest I further debug. I work frontend mostly, so I apologize for my ignorance in this.

          – Rich Staats
          Apr 9 '12 at 21:38













          You can try turning on logging and seeing what actions its taking.

          – Andrew M.
          Apr 10 '12 at 5:21







          You can try turning on logging and seeing what actions its taking.

          – Andrew M.
          Apr 10 '12 at 5:21




















          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%2f377431%2fredirect-anything-within-attachments-directory-up-one-level-but-also-removing%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

          As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

          Українські прізвища Зміст Історичні відомості |...

          Список ссавців Італії Природоохоронні статуси | Список |...