SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rewrite redirect help needed

    Trying to redirect this format

    archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html

    to this:

    archive/index.php/t-59411.html

    I can only find examples of what to do if they were querystrings.

    thanks!!
    Free Science Homework Help
    http://www.physicsforums.com

  2. #2
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fyi, I am looking for a redirect. the first url does not exist, it only exists in the second format
    Free Science Homework Help
    http://www.physicsforums.com

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Code:
    Redirect permanent /archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html http://example.com/archive/index.php/t-59411.html
    replace example.com with your domain

    (see http://httpd.apache.org/docs/current....html#redirect)
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Code:
    Redirect permanent /archive/topic/t-59411_Nastase_RHIC_produces_black_holes.html http://example.com/archive/index.php/t-59411.html
    replace example.com with your domain

    (see http://httpd.apache.org/docs/current....html#redirect)
    The number is dynamic though and the keywords are too, I'm going to try this:

    RewriteRule ^archive/topic/t-([0-9]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
    Free Science Homework Help
    http://www.physicsforums.com

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by dethfire View Post
    The number is dynamic though and the keywords are too, I'm going to try this:

    RewriteRule ^archive/topic/t-([0-9]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
    Looks good! I would add one slash just to be sure

    Code:
    RewriteRule ^archive/topic/t-([0-9]+)([[a-zA-Z0-9_]+).html$ /archive/index.php/t-$1.html [R=301,L]
    Just to be clear, but it might work fine without (my .htaccess is getting a bit rusty)
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Wizard dethfire's Avatar
    Join Date
    Aug 2000
    Posts
    2,477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got what I wanted mostly from this:

    RewriteRule ^archive/topic/t-([0-9-]+)([[a-zA-Z0-9_]*).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/topic/t-([0-9-]+)$ archive/index.php/t-$1.html [R=301,L]

    RewriteRule ^archive/topic/([0-9-]+).html$ archive/index.php/t-$1.html [R=301,L]

    RewriteRule ^archive/t-([0-9-]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/t-([0-9]+)$ archive/index.php/t-$1.html [R=301,L]


    I assume it's not very efficent. Is there a more compact way to do this?
    Free Science Homework Help
    http://www.physicsforums.com

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by dethfire View Post
    I assume it's not very efficent. Is there a more compact way to do this?
    There is, but it's highly unreadable and not any more efficient in terms of speed. I'd just stick with what you have now
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    I'll give it a go for funsies.

    RewriteRule ^archive/(?:topic/)?(?:t-)?(\d+)[^/]*\.html$ /archive/index.php/t-$1.html [R=301,L]
    "First make it work. Then make it better."

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I'll give it a go for funsies.

    RewriteRule ^archive/(?:topic/)?(?:t-)?(\d+)[^/]*\.html$ /archive/index.php/t-$1.html [R=301,L]
    That misses two of the rules

    Code:
    RewriteRule ^archive/topic/t-([0-9-]+)([[a-zA-Z0-9_]*).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/topic/t-([0-9-]+)$ archive/index.php/t-$1.html [R=301,L]
    
    RewriteRule ^archive/topic/([0-9-]+).html$ archive/index.php/t-$1.html [R=301,L]
    
    RewriteRule ^archive/t-([0-9-]+)([[a-zA-Z0-9_]+).html$ archive/index.php/t-$1.html [R=301,L]
    RewriteRule ^archive/t-([0-9]+)$ archive/index.php/t-$1.html [R=301,L]
    because they don't end in .html, so that should be an optional group as well.

    Off Topic:

    I never knew Apache 2 supported non-matching groups, good to know!
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  10. #10
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Oops. You're right.

    If the extension is optional, then we may be able to get away with leaving off the end of the pattern altogether.

    RewriteRule ^archive/(?:topic/)?(?:t-)?(\d+) /archive/index.php/t-$1.html [R=301,L]
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •