htaccess question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • X37375787
    • Jul 2026

    #1

    htaccess question

    On one of my sites I run WordPress and have permalinks setup via mod_rewrite. Currently, the posts appear as directories like

    http://www.domain.com/category/postname/

    I know I could change the permalink structure in the script itself to postname.html - but then the pages indexed by SEs would return 404s all across the site.

    Is there a way to divert requests for directories to the virtual .html files as specified by the new rewrite rules?
  • X37375787

    #2
    So

    http://www.domain.com/category/postname/

    would automatically 301 to

    http://www.domain.com/category/postname.html

    Comment

    • pornpf69
      Too lazy to set a custom title
      • Jun 2004
      • 15782

      #3
      I am sorry but I can help on this matter...good luck with it!

      Comment

      • X37375787

        #4
        Originally posted by pornpf69
        I am sorry but I can help on this matter...good luck with it!
        I guess you mean to say you can't help with this matter

        Comment

        • Realpascal
          Confirmed User
          • Jun 2005
          • 2119

          #5
          Bump for you.
          OMGWTFBBQ

          Comment

          • kektex
            Confirmed User
            • Mar 2005
            • 1813

            #6
            try webmasterworld.com
            They have a bunch of very knowledgeable people on the apache forum
            exgfmovies.com, exgfclips.com, datesx.com, gayboards.com and more!

            Comment

            • The Sultan Of Smut
              Confirmed User
              • Dec 2004
              • 4325

              #7
              I searched for this:

              http://www.google.com/search?sourcei...q=htaccess+301

              and found this:

              http://www.tamingthebeast.net/articl...1-redirect.htm

              Comment

              • psili
                Confirmed User
                • Apr 2003
                • 5526

                #8
                Haven't tested it, but something like:

                Code:
                RewriteEngine on
                RewriteRule categories/(.*)/? categories/$1.html [R=301]
                Your post count means nothing.

                Comment

                • psili
                  Confirmed User
                  • Apr 2003
                  • 5526

                  #9
                  Here's a handly little rewrite cheat sheet for you mod rewrite fans from some dude who apparently digs on jack daniels:

                  http://www.ilovejackdaniels.com/mod_...heat_sheet.png
                  Your post count means nothing.

                  Comment

                  • pornpf69
                    Too lazy to set a custom title
                    • Jun 2004
                    • 15782

                    #10
                    Originally posted by Equinox
                    I guess you mean to say you can't help with this matter
                    that is what I meant...

                    Comment

                    • J.P.
                      Confirmed User
                      • Jun 2004
                      • 689

                      #11
                      psili, that code won't work, because .* matches everything 0 or more times and /? matches a character 0 times or once... so this code of yours would match
                      http://www.domain.com/category/postname.html also

                      Code:
                      RewriteEngine on
                      RewriteRule $categories/([^/\.]+)/?^ categories/$1.html [R=301]
                      this would match everything except for / and . 1 or more times, so http://www.domain.com/category/postname.html would not match...

                      This is not tested also, so maybe there are errors in this too

                      Note that the above code will work in .htacces only, to use it in httpd.conf you should add / right before the categories, like this:

                      Code:
                      RewriteEngine on
                      RewriteRule $/categories/([^/\.]+)/?^ /categories/$1.html [R=301]
                      Julio
                      Webmasters! Looking for new affiliate programs to promote?
                      Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

                      Comment

                      • jimmyf
                        OU812
                        • Feb 2001
                        • 12651

                        #12
                        Originally posted by The Sultan Of Smut

                        tamingthebeast.net

                        dam good one, explanes it the best I've ever seen.
                        Epic CashEpic Cash works for me
                        Solar Cash Paysite Plugin
                        Gallery of the day freesites,POTD,Gallery generator with free hosting

                        Comment

                        • X37375787

                          #13
                          thanks for the info guys. The example I posted was rather specific, the solution I need will be a little more complex since I am looking into redirecting URLs in different subfolders, not just /categories/. But nonetheless, I can start with the info that was posted here.

                          Comment

                          • J.P.
                            Confirmed User
                            • Jun 2004
                            • 689

                            #14
                            Not a problem:

                            Code:
                            RewriteEngine on
                            RewriteRule $(dir1|dir2|dir3|dir4)/([^/\.]+)/?^ $1/$2.html [R=301]
                            Julio
                            Webmasters! Looking for new affiliate programs to promote?
                            Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

                            Comment

                            Working...