#1
  1. No Profile Picture
    rubbish in javascript
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    London
    Posts
    717
    Rep Power
    17

    htaccess rewrite rule to work with wordpress defaults


    Attempting to exclude a folder ‘test’ from the wordpress rewrite rules in the htaccess file and give it a unique rewrite. Test isn’t a real folder.

    So this:
    Code:
    /test/post1/
    or this
    Code:
    /test/post1
    should rewrite to
    Code:
    /index.php?pagename=$1
    where $1 is the posttitle e.g. post1. I think I have the exclusion working as a RewriteCond (see below) – how do I add the RewriteRule for it?

    Code:
    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_URI} !^/(test|test/.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,326
    Rep Power
    9645
    Don't worry about the RewriteCond - just make a Rule that goes before it.

    And don't modify the WordPress stuff. Leave it as they wrote (more or less) so there's no confusion later about where this "test" thing came from.

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^test/([^/+)/?$ index.php?pagename=$1 [L]
    
    # BEGIN WordPress
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
    
    </IfModule>
  4. #3
  5. No Profile Picture
    rubbish in javascript
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    London
    Posts
    717
    Rep Power
    17
    Thanks, I think it's missing a square bracket like so:

    Code:
    RewriteRule ^test/([^/]+)/?$ index.php?pagename=$1 [L]
    mmm it sort of works.
    /test/ goes to a page correctly - test is the stub for a page in wordpress, I guess the defaults are handling that.
    /test/post1/ redirects (not rewrites) to /post1/ - post1 is the stub for a post so that doesn't seem to work the defaults are still catching it.
    A fake pathway such as /test/nothing/ however does work, no redirect, it rewrites to the index.php which shows a no posts result.
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,326
    Rep Power
    9645
    Is WordPress doing the redirect? Because it's not the .htaccess.
  8. #5
  9. No Profile Picture
    rubbish in javascript
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    London
    Posts
    717
    Rep Power
    17
    I'm using post name as the permalink structure in wordpress, other than that I haven't set any redirects via filters in wordpress. Below is the full output from Rewrite Analyzer. Everything looks ok to me but maybe this one is an issue?

    Code:
    [^/]+/([^/]+)/?$	
         attachment: ([^/]+)
    These should all be originating from the rewrite rules in the htaccess though if I've not added any via filters right?


    Code:
    Pattern	Substitution
    ^wp-json/?$	
         rest_route: /
    ^wp-json/(.*)?	
         rest_route: /(.*)?
    ^index.php/wp-json/?$	
         rest_route: /
    ^index.php/wp-json/(.*)?	
         rest_route: /(.*)?
    wpsc_cart_orders/?$	
          post_type: wpsc_cart_orders
    wpsc_cart_orders/feed/(feed|rdf|rss|rss2|atom)/?$	
          post_type: wpsc_cart_orders
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/(feed|rdf|rss|rss2|atom)/?$	
          post_type: wpsc_cart_orders
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/page/([0-9]{1,})/?$	
          post_type: wpsc_cart_orders
              paged: ([0-9]{1,})
    category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$	
      category_name: (.+?)
               feed: (feed|rdf|rss|rss2|atom)
    category/(.+?)/(feed|rdf|rss|rss2|atom)/?$	
      category_name: (.+?)
               feed: (feed|rdf|rss|rss2|atom)
    category/(.+?)/embed/?$	
      category_name: (.+?)
              embed: true
    category/(.+?)/page/?([0-9]{1,})/?$	
      category_name: (.+?)
              paged: ([0-9]{1,})
    category/(.+?)/?$	
      category_name: (.+?)
    tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
                tag: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
                tag: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    tag/([^/]+)/embed/?$	
                tag: ([^/]+)
              embed: true
    tag/([^/]+)/page/?([0-9]{1,})/?$	
                tag: ([^/]+)
              paged: ([0-9]{1,})
    tag/([^/]+)/?$	
                tag: ([^/]+)
    type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
        post_format: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
        post_format: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    type/([^/]+)/embed/?$	
        post_format: ([^/]+)
              embed: true
    type/([^/]+)/page/?([0-9]{1,})/?$	
        post_format: ([^/]+)
              paged: ([0-9]{1,})
    type/([^/]+)/?$	
        post_format: ([^/]+)
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/?$	
         attachment: ([^/]+)
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    wpsc_cart_orders/[^/]+/attachment/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    wpsc_cart_orders/([^/]+)/embed/?$	
    wpsc_cart_orders: ([^/]+)
              embed: true
    wpsc_cart_orders/([^/]+)/trackback/?$	
    wpsc_cart_orders: ([^/]+)
                 tb: 1
    wpsc_cart_orders/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
    wpsc_cart_orders: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
    wpsc_cart_orders: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/([^/]+)/page/?([0-9]{1,})/?$	
    wpsc_cart_orders: ([^/]+)
              paged: ([0-9]{1,})
    wpsc_cart_orders/([^/]+)/comment-page-([0-9]{1,})/?$	
    wpsc_cart_orders: ([^/]+)
              cpage: ([0-9]{1,})
    wpsc_cart_orders/([^/]+)?(:/([0-9]+))?/?$	
    wpsc_cart_orders: ([^/]+)?
               page: (:/([0-9]+))?
    wpsc_cart_orders/[^/]+/([^/]+)/?$	
         attachment: ([^/]+)
    wpsc_cart_orders/[^/]+/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    wpsc_cart_orders/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    wpsc_cart_orders/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    wpsc_cart_orders/[^/]+/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    notes/[^/]+/attachment/([^/]+)/?$	
         attachment: ([^/]+)
    notes/[^/]+/attachment/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    notes/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    notes/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    notes/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    notes/[^/]+/attachment/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    notes/([^/]+)/embed/?$	
               note: ([^/]+)
              embed: true
    notes/([^/]+)/trackback/?$	
               note: ([^/]+)
                 tb: 1
    notes/([^/]+)/page/?([0-9]{1,})/?$	
               note: ([^/]+)
              paged: ([0-9]{1,})
    notes/([^/]+)/comment-page-([0-9]{1,})/?$	
               note: ([^/]+)
              cpage: ([0-9]{1,})
    notes/([^/]+)?(:/([0-9]+))?/?$	
               note: ([^/]+)?
               page: (:/([0-9]+))?
    notes/[^/]+/([^/]+)/?$	
         attachment: ([^/]+)
    notes/[^/]+/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    notes/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    notes/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    notes/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    notes/[^/]+/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    robots\.txt$	
             robots: 1
    .*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$	
               feed: old
    .*wp-app\.php(/.*)?$	
              error: 403
    .*wp-register.php$	
           register: true
    feed/(feed|rdf|rss|rss2|atom)/?$	
               feed: (feed|rdf|rss|rss2|atom)
    (feed|rdf|rss|rss2|atom)/?$	
               feed: (feed|rdf|rss|rss2|atom)
    embed/?$	
              embed: true
    page/?([0-9]{1,})/?$	
              paged: ([0-9]{1,})
    comments/feed/(feed|rdf|rss|rss2|atom)/?$	
               feed: (feed|rdf|rss|rss2|atom)
       withcomments: 1
    comments/(feed|rdf|rss|rss2|atom)/?$	
               feed: (feed|rdf|rss|rss2|atom)
       withcomments: 1
    comments/embed/?$	
              embed: true
    search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$	
                  s: (.+)
               feed: (feed|rdf|rss|rss2|atom)
    search/(.+)/(feed|rdf|rss|rss2|atom)/?$	
                  s: (.+)
               feed: (feed|rdf|rss|rss2|atom)
    search/(.+)/embed/?$	
                  s: (.+)
              embed: true
    search/(.+)/page/?([0-9]{1,})/?$	
                  s: (.+)
              paged: ([0-9]{1,})
    search/(.+)/?$	
                  s: (.+)
    author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
        author_name: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
        author_name: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    author/([^/]+)/embed/?$	
        author_name: ([^/]+)
              embed: true
    author/([^/]+)/page/?([0-9]{1,})/?$	
        author_name: ([^/]+)
              paged: ([0-9]{1,})
    author/([^/]+)/?$	
        author_name: ([^/]+)
    ([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
                day: ([0-9]{1,2})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
                day: ([0-9]{1,2})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/embed/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
                day: ([0-9]{1,2})
              embed: true
    ([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
                day: ([0-9]{1,2})
              paged: ([0-9]{1,})
    ([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
                day: ([0-9]{1,2})
    ([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/([0-9]{1,2})/embed/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
              embed: true
    ([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
              paged: ([0-9]{1,})
    ([0-9]{4})/([0-9]{1,2})/?$	
               year: ([0-9]{4})
           monthnum: ([0-9]{1,2})
    ([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$	
               year: ([0-9]{4})
               feed: (feed|rdf|rss|rss2|atom)
    ([0-9]{4})/embed/?$	
               year: ([0-9]{4})
              embed: true
    ([0-9]{4})/page/?([0-9]{1,})/?$	
               year: ([0-9]{4})
              paged: ([0-9]{1,})
    ([0-9]{4})/?$	
               year: ([0-9]{4})
    .?.+?/attachment/([^/]+)/?$	
         attachment: ([^/]+)
    .?.+?/attachment/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    .?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    .?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    .?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    .?.+?/attachment/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    (.?.+?)/embed/?$	
           pagename: (.?.+?)
              embed: true
    (.?.+?)/trackback/?$	
           pagename: (.?.+?)
                 tb: 1
    (.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$	
           pagename: (.?.+?)
               feed: (feed|rdf|rss|rss2|atom)
    (.?.+?)/(feed|rdf|rss|rss2|atom)/?$	
           pagename: (.?.+?)
               feed: (feed|rdf|rss|rss2|atom)
    (.?.+?)/page/?([0-9]{1,})/?$	
           pagename: (.?.+?)
              paged: ([0-9]{1,})
    (.?.+?)/comment-page-([0-9]{1,})/?$	
           pagename: (.?.+?)
              cpage: ([0-9]{1,})
    (.?.+?)?(:/([0-9]+))?/?$	
           pagename: (.?.+?)?
               page: (:/([0-9]+))?
    [^/]+/attachment/([^/]+)/?$	
         attachment: ([^/]+)
    [^/]+/attachment/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    [^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    [^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    [^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    [^/]+/attachment/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
    ([^/]+)/embed/?$	
               name: ([^/]+)
              embed: true
    ([^/]+)/trackback/?$	
               name: ([^/]+)
                 tb: 1
    ([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
               name: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    ([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
               name: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    ([^/]+)/page/?([0-9]{1,})/?$	
               name: ([^/]+)
              paged: ([0-9]{1,})
    ([^/]+)/comment-page-([0-9]{1,})/?$	
               name: ([^/]+)
              cpage: ([0-9]{1,})
    ([^/]+)?(:/([0-9]+))?/?$	
               name: ([^/]+)?
               page: (:/([0-9]+))?
    [^/]+/([^/]+)/?$	
         attachment: ([^/]+)
    [^/]+/([^/]+)/trackback/?$	
         attachment: ([^/]+)
                 tb: 1
    [^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    [^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
         attachment: ([^/]+)
               feed: (feed|rdf|rss|rss2|atom)
    [^/]+/([^/]+)/comment-page-([0-9]{1,})/?$	
         attachment: ([^/]+)
              cpage: ([0-9]{1,})
    [^/]+/([^/]+)/embed/?$	
         attachment: ([^/]+)
              embed: true
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,079
    Rep Power
    4101
    I'd guess that Wordpress sees that the URL you're trying to create is not the correct URL for your post/page so it's redirecting to the proper url.

    What exactly are you trying to do and why?
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. No Profile Picture
    rubbish in javascript
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    London
    Posts
    717
    Rep Power
    17
    I have a second posts page on my Wordpress site that displays all posts from one category, the category is 'test' and the page's stub in Wordpress is 'test' so the page displays at /test/. The page rewrites through page.php as all pages do. There is no folder or file called test in the site structure to interfere with the rewrite.

    All posts that are clicked on on the page should show as if they are within /test/ so for example post1 would be at /test/post1/

    Code:
    /test/post1/
    needs to rewrite to
    Code:
    /index.php?pagename=$1
    where $1 is the posttitle e.g. post1, so that the single single post php page, post.php can pick it up.

IMN logo majestic logo threadwatch logo seochat tools logo