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.

need help with htaccess

Discussion in 'Apache' started by bobestes, Apr 10, 2015.

  1. #1
    i need to create a redirect to a non existing page.

    here is my code and the site is on shared hosting

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index2\.php#!(.*)$ /index2\.php/$1 [R=301,L]
    </IfModule>

    this would be my url ttp://sub.domain.com/index2.php#!time/
    i would like to redirect avery request with "#!string" to new url (same page) - ttp://sub.domain.com/index2.php/time/

    i know that the code above needs
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    to be added but it doesnt even makes the redirect to 404. the url doesnt change.
    SEMrush
    thanks
     
    bobestes, Apr 10, 2015 IP
    SEMrush
  2. jeremym80

    jeremym80 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    I am not to sure you will actually need a RewriteCond. If you just want it to redirect it should be fairly simple. I am going to test a few things and get back to you and see.
     
    jeremym80, Apr 10, 2015 IP
  3. bobestes

    bobestes Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #3
    Waiting, thanks.
     
    bobestes, Apr 10, 2015 IP
  4. jeremym80

    jeremym80 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    I would think you should be able to do it simply similar to this example I found.

    RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$    get_product_by_name.php?category_name=$1&product_name=$2    [NC,L]
    Code (markup):
    The pattern in the first part, then where to send it in the second part and of course with a 301 at the end. Or I suppose a RewriteCond can work as well with something like this example.

    RewriteCond %{HTTP_HOST} old_domain\.com [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
    Code (markup):
    If you are getting 404 errors, something is screwy with the way it was written in the htaccess file. I know its not the best help, but keeping it as simple as possible is probably the best way to go about it.
     
    jeremym80, Apr 10, 2015 IP
  5. bobestes

    bobestes Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #5
    well, it looks tome me exaclty like what i have been doing. where does it differ?
     
    bobestes, Apr 10, 2015 IP
  6. jeremym80

    jeremym80 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    Try this maybe.

    RewriteRule ^index2\.php#!(.*)   /$1  [R=301,L]
    Code (markup):
     
    jeremym80, Apr 10, 2015 IP
  7. bobestes

    bobestes Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #7
    still nothing
     
    bobestes, Apr 10, 2015 IP
  8. jeremym80

    jeremym80 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    I may be missing something small.... did you try both of the ways below? I think the simplicity is on the right track though and may just have to wait until someone else takes a look to clean it up.
    RewriteRule ^index2\.php#!(.*)    /$1 [R=301,L]
    RewriteRule ^index2\.php#!(.*)$   /$1 [R=301,L]
    Code (markup):
     
    jeremym80, Apr 10, 2015 IP
  9. bobestes

    bobestes Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #9
    still, the url doesnt change
     
    bobestes, Apr 10, 2015 IP