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.

.htaccess needs for rule to redirect

Discussion in 'Apache' started by ma3hd, Feb 21, 2013.

  1. #1
    Hello ,

    I have page like that : http://www.mydomain.com/name1-rates.html
    i wan to permanent redirect it to :
    http://www.mydomain.com/name1rates.html

    Also needs to redirect all another page have words ( rates ) to index
     
    ma3hd, Feb 21, 2013 IP
  2. eldiablo

    eldiablo Active Member

    Messages:
    200
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    80
    #2
    eldiablo, Feb 21, 2013 IP
  3. ma3hd

    ma3hd Active Member

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks eldiable ,,,

    it's fine ,,, but name1 i changed varaiable on some of pages as : name1 , name2 , name3 ...etc

    I try to make it as this
    Redirect 301 /$1-rates.html http://www.mydomain.com/$1rates.html

    But not work ,,, kindly can help me in this ?
     
    ma3hd, Feb 22, 2013 IP
  4. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #4
    This code should do the trick for you:
    RewriteEngine On
    RewriteBase /
    RewriteRule ^name([0-9]+)-rates.html$ /name$1rates.html [L,R=301] #rewrites all nameX files
    RewriteRule ^([^/]+)-rates.html$ /? [L,R=301] #rewrites all other '-rates' pages to home page
    Code (markup):
    Cheers!
     
    pr0t0n, Feb 28, 2013 IP
  5. ma3hd

    ma3hd Active Member

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Dear Proton thanks for reply ...

    but your code not work
     
    ma3hd, Feb 28, 2013 IP
  6. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #6
    Interesting. Perhaps you should check few things then:
    • Is your web site on a linux or a windows server?
    • If linux, is it the apache or some other type of a server?
    • If linux and apache, does it have mod rewrite support at all?
    To test this all, put some simple mod rewrite rule in your .htaccess just for testing purposes. For example:
    RewriteEngine on
    RewriteRule ^google\.html$ http://www.google.com/ [R]
    Code (markup):
    After that try just hitting yourdomain.com/google.html and if it doesn't redirect to google then mod rewrite is not even working for your account.
     
    pr0t0n, Mar 1, 2013 IP
  7. ma3hd

    ma3hd Active Member

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    Dear Proton thanks for reply ...

    Yes sir i have already scripts work with mod rewrite very good as vbseo ,,, games script .. wordpress

    But this is special script i programing it ...

    and this link : http://www.mydomain.com/name-rates.html

    Name : is variable changed every page

    i need only remove "-" between name and rates .

    this command
    
    Redirect 301 /name1-rates.html http://www.mydomain.com/name1rates.html
    
    PHP:
    but i must be write name variable in htaccess to every page

    as
    
    Redirect 301 /myname-rates.html http://www.mydomain.com/mynamerates.html
    Redirect 301 /myname1-rates.html http://www.mydomain.com/myname1rates.html
    Redirect 301 /myname2-rates.html http://www.mydomain.com/myname2rates.html
    
    PHP:
    ETC ...

    and i have thousands of pages
     
    ma3hd, Mar 1, 2013 IP
  8. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #8
    Oh... so "name" is actually a variable, and not a fixed word. So then try something like this:
    RewriteRule ^([^/]+)-rates.html$ /$1rates.html [L,R=301]
    Code (markup):
    And make sure you have "RewriteEngine On" prior to that line.

    Basically this example should just loose - in your .html file name.

    Additionally, if the above example is not working properly again, make sure your destination page actually works when you try to open it directly. So for example try opening yourdomain.com/mynamerates.html directly in browser and check if it loads at all.
     
    pr0t0n, Mar 1, 2013 IP
  9. ma3hd

    ma3hd Active Member

    Messages:
    116
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #9
    thanks but not redirect also
     
    ma3hd, Mar 1, 2013 IP
  10. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #10
    I believe the rule is correct, but the problem is related to something else. Perhaps someone else will notice something I'm not and provide different instructions though.
     
    pr0t0n, Mar 1, 2013 IP