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.

Advanced htaccess 301 redirection

Discussion in 'Apache' started by Preseren, Jun 19, 2009.

  1. #1
    Hey

    I've read the sticky on redirection, but didn't find (or I just didn't get it) the info.
    My urls have changed from www.domain.com/index.php/whatever.html to www.domain.com/whatever.html
    There are literally thousands of this pages that have changed, so I'm looking for one redirect command that will redirect all index.php to non index.php
    Can anyone give me an example what to write into my htaccess?

    Thanks!
     
    Preseren, Jun 19, 2009 IP
  2. gregberwitz

    gregberwitz Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^index.php/(.*)$ $1
    
    Code (markup):
     
    gregberwitz, Jun 19, 2009 IP
  3. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #3
    @gregberwitz, sorry, but it does not work, I still get a 404. I forgot to say, that its joomla working with sh404, that means that other rewrites are allready in htaccess.
     
    Preseren, Jun 20, 2009 IP
  4. gregberwitz

    gregberwitz Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Post the existing htaccess please.
     
    gregberwitz, Jun 20, 2009 IP
  5. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #5
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^index.php/(.*)$ $1

    Options +FollowSymLinks

    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
    RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    RewriteRule ^(.*)$ index.php [F,L]

    RewriteCond %{HTTP_HOST} ^debate-motions\.info$ [NC]
    RewriteRule ^(.*)$ http://www.debate-motions.info/$1 [R=301,L]

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^debate-motions.info$ [OR]
    RewriteCond %{HTTP_HOST} ^www.debate-motions.info$
    RewriteRule ^/index.php?$ http://www.debate-motions.info/index.php?option=com_frontpage&Itemid=1 [R=301,L]
     
    Preseren, Jun 21, 2009 IP
  6. gregberwitz

    gregberwitz Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try to change
    RewriteRule ^index.php/(.*)$ $1
    to
    RewriteRule ^index.php/(.*)$ $1 [L]
     
    gregberwitz, Jun 21, 2009 IP
  7. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #7
    no, its still loads the URL with index.php and gives a 404.
    Any other idea please?
     
    Preseren, Jun 21, 2009 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    Take what you added out.

    You don't need the RewriteCond for -f and -d in with this RewriteRule unless you have a real folder named "/index.php/" because they will never match.
    You don't need RewriteBase because you'll be doing an external redirect with the full URL so that search-engines/visitors can be notified of the address change.

    What you've tried in this thread is missing a 301 redirect flag on the end nor does it implicitly trigger an external redirect via a full URL in the destination, so instead of being rewritten and immediately directing the visitor to the new URL, it keeps processing. Not good.

    After the first existing occurance of "RewriteEngine on", you will add the new RewriteRule.

    Options +FollowSymLinks
    
    RewriteEngine On
    
    [color=#990000]RewriteRule ^index\.php(/.+)$ http://%{HTTP_HOST}$1 [NC,R=301][/color]
    
    RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
    Code (markup):
     
    joebert, Jun 21, 2009 IP
  9. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #9
    Hey, joebert thanks tor the explanation, but sadly the links are still showing 404
    This is an example of a link that should be rewritten, but it does not get there
    http://www.debate-motions.info/index.php/Debate-motions/Debate-formats/
    it should read http://www.debate-motions.info/Debate-motions/Debate-formats/

    EDIT: Just noticed, after I put it where you say it didn't work. So I figured that I should move it, and I moved it after the original rewrite does its job. Now it turns the URL to
    http://www.debate-motions.info/Debate-formats/
    So it takes one step too much out of the URL. Can we change that? Now we are at least on the right way
     
    Preseren, Jun 21, 2009 IP
  10. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #10
    This needs to be your first Rewrite because you are moving from an old way of doing things to a new way. If you start working with the URL before you've made sure it's not an old-style request, you're going to get unexpected results sooner or later.

    When it's setup as the first RewriteRule and gives you a 404, what is the address you are trying, and what is the address in the title bar ?
     
    joebert, Jun 22, 2009 IP
  11. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #11
    Hey

    Thanks all for your help, Ill try it aga in and post the URL's in a day or two, a lot of people just visiting the site, so I don't want to mess around with it just now.

    P.
     
    Preseren, Jun 22, 2009 IP
  12. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Looks like a wordpress install. Take a look at Dashboard -> Settings and make sure the two url fields don;t have the index.php in there.

    Also: http:// htaccess.wordpress.com/2007/12/08/removing-indexphp-with-htaccess/
     
    theapparatus, Jun 22, 2009 IP
  13. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #13
    Preseren, Jun 23, 2009 IP
  14. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #14
    What are the addresses shown in the address bar after the redirection occurs ?
     
    joebert, Jun 23, 2009 IP
  15. Preseren

    Preseren Active Member

    Messages:
    275
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #15
    They are as I pasted them above
     
    Preseren, Jun 23, 2009 IP
  16. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #16
    So, the address you click on, and the resulting address in the bar are the same but you're getting a 404 when the RewriteRule is in place ?
     
    joebert, Jun 23, 2009 IP