Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Redirect old url to new url by cuting some word

    I just change all url in my website around 2000 url.

    The pattern of old url have fix pattern such as www.example.com/book-XXXXXXXX.html

    where book- is fix and XXXXXXXX is variable.

    I change the new url by delete fixing word book-.

    so www.example.com/book-XXXXXXXX.html is changed to www.example.com/XXXXXXXX.html

    Anyone please kindly advise how to write in .htaccess to redirect all old url to new url.

    I have try 2 times as follows but it does not work.

    RewriteCond http://www.example.com/book-^(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    RewriteCond http://www.example.com/book-(.*) [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    Many thanks in advance.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try
    Code:
    RewriteRule ^book\-(.*)$ /$1 [R=301,L]
    without any RewriteCond
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    DooDoo (01-26-2011)

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    49
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I tried doing a 301, too but it resulted in not being able to access my site at all. I'd like the 301 to make the old files redirect to the new ones.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Did you remove the RewriteCond like abduraooft suggested? Your original RewriteCond is missing the variable to test against. See the example in the top-right of the mod_rewrite cheat sheet.

  • #5
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Did you remove the RewriteCond like abduraooft suggested? Your original RewriteCond is missing the variable to test against. See the example in the top-right of the mod_rewrite cheat sheet.
    Yes, I did and it work now. A little problem is some url that have book-book-XXXXX.html will have double redirect.

    I am very new on mod-rewrite , if you have any more suggestion please kindly advise.

    RewriteCond , It has many variable, which one should I use it ?

    %{REQUEST_FILENAME} or any one.

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    A little problem is some url that have book-book-XXXXX.html will have double redirect.
    Code:
    RewriteRule ^(book\-)+(.*)$ /$2 [R=301,L]
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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