1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with .htaccess

Discussion in 'Apache' started by sagetips, Jul 6, 2006.

  1. #1
    Hello -

    I've moved my Wordpress blog to the root directory and decided to eliminate the post id from the permalink. So now I'm trying to figure out the right .htaccess statement to use to redirect thusly:

    From
    www.mysite.com/blog/157/best-post.php/
    SEMrush
    to
    www.mysite.com/best-post.php/

    I've found guidance on going to www.mysite.com/157/best-post.php/
    but can't figure out how to get rid of the post id number.

    Can someone help out an .htaccess novice?

    Thanks
     
    sagetips, Jul 6, 2006 IP
    SEMrush
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would try :
    Options +FollowSymlinks
    RewriteEngine on 
    RewriteRule ^blog\/\d+\/(.*)$   /$1  [QSA,L,R=301]
    Code (markup):
    Jean-Luc
     
    Jean-Luc, Jul 6, 2006 IP
    sagetips likes this.
  3. sagetips

    sagetips Peon

    Messages:
    239
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sagetips, Jul 7, 2006 IP
  4. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To eliminate the /157 :
    RewriteRule ^blog\/\d+\/(.*)$ $1 [L,redirect=permanent]
    Code (markup):
    \/ should be used for a / in the left part.
    \d+ means any number

    Jean-Luc
     
    Jean-Luc, Jul 7, 2006 IP
  5. sagetips

    sagetips Peon

    Messages:
    239
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    GRRRR! Still no luck.

    I probably should have noted that I'm using 1and1 hosting which I know has its quirks.

    When I tried

    RewriteRule ^blog\/\d+\/(.*)$ $1 [L,redirect=permanent]
    Code (markup):
    the result goes back to:

    www.mysite.com/blog/157/best-post.php/

    This seems to happen with all changes I try after the "blog/" in
    RewriteRule ^heloc-blog/(.*)$ $1 [L,redirect=permanent]


    Here's some of the trial and error stuff I've tried w/o luck:
    RewriteRule ^blog\/\d+\/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog\/\d+/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/\d+(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/d+(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog\d+(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/\d+(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/(\d+)(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/(d+)/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/\d+(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog\(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/\d+/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/\d+\/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog\/\d+\/(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/(\d+)(.*)$ $1 [L,redirect=permanent]
    RewriteRule ^blog/(.*)$ $1 [L,redirect=permanent]

    Any other ideas?
     
    sagetips, Jul 7, 2006 IP
  6. brunozugay

    brunozugay Peon

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's a long shot, but try this:

    RewriteRule /blog/[0-9]+/(.*) /$1 [L,redirect=permanent]
     
    brunozugay, Jul 7, 2006 IP
    sagetips likes this.
  7. sagetips

    sagetips Peon

    Messages:
    239
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That Did It! Using Bruno's suggestion but replacing the initial / with ^ does the trick:

    RewriteRule ^blog/[0-9]+/(.*) /$1 [L,redirect=permanent]
    Code (markup):
    Many thanks to Jean and Bruno for taking time to help. Hope I can pay forward the favor.
     
    sagetips, Jul 8, 2006 IP
  8. brunozugay

    brunozugay Peon

    Messages:
    150
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm glad I was able to be of help. :)
     
    brunozugay, Jul 8, 2006 IP