SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: 301..302..

  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry 301..302..

    I've set up recently some ModRewrites..

    RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z1-9_]+)$ index.php?var1=$1&var2=$2 [L,NC]
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&var2=$3&var5=$5 [L]

    I've tried altering [L] to [L,R=permanent] but this makes all my links and pages not found.

    I tried adding just header("HTTP/1.1 301 Moved Permanently"); in to the top header but it throws a wobbly too.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lbts,

    WHY do you think the No Case flag is useful in a RewriteRule?

    Try:
    Code:
    RewriteEngine on
    # RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z1-9_]+)$ index.php?var1=$1&var2=$2 [L]
    # That's duplicated by the optional atom in the following RewriteRule
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&var2=$3&var5=$5 [L]
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh DK, Why does it seem you're the only person on this whole site who knows anything about ModRewrite

    So, I've trimmed it so it looks something like;

    Code:
    RewriteCond %{HTTP_REFERER} !^http://www.somedomain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.somedomain.com$    [NC]
    RewriteEngine on
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?$ index.php?var1=$1&var2=$3&var5=$5 [L,NC]
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&var2=$3&var5=$5 [L,NC]
    Will this now stop it being a temporary redirect and make it a permanent?
    And is there any way of losing the 2nd line to allow for '/' or the lack of in just 1 ??

    I was more worried all my search engine efforts will be thwarted by every page on the site now being 301 (as AWstats seems to keep telling me).

    Thanks for the help - as always!

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Ehm... 301 is a permanent redirect. It's also the redirect you want to give your PR from the previous location to the new location.

    That being said, your script currently doesn't externally redirect at all. You should change [L,NC] to [L,NC,R=301] and then remove the NC because you really don't need in the rules -- you already have a-zA-Z in the regex so it's already case insensitive. So, change [L,NC] to [L,R=301]
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did it one step at a time and removed NC, which worked..

    Code:
    RewriteCond %{HTTP_REFERER} !^http://www.site.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.site.com$    [NC]
    RewriteEngine on
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?$ index.php?var1=$1&var2=$3&var5=$5 [L]
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&var2=$3&var5=$5 [L]
    BUT, when I then add [L,R=301] to it, my site stops working and every link goes to a 404!! Like;

    Code:
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?$ index.php?var1=$1&var2=$3&var5=$5 [L,R=301]
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&var2=$3&var5=$5 [L,R=301]
    What am I doing wrong???

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    And there is nothing else in your .htaccess?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My full HTAccess looks like;


    Code:
    RewriteEngine on
    # -FrontPage-
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName site.com
    AuthUserFile /home/sitecom/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/sitecom/public_html/_vti_pvt/service.grp
    RewriteCond %{HTTP_REFERER} !^http://www.site.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.site.com$    [NC]
    RewriteEngine on
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?$ index.php?var1=$1&var2=$3&var5=$5 [L]
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&vae2=$3&var5=$5 [L]

  8. #8
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No idea why it's still making all my pages 302 instead of 301?

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Simple: Unless otherwise directed, mod_rewrite makes TEMPORARY redirections (302) rather than PERMANENT redirections (301). Since I don't see a 301 anywhere above, they're all temporary.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But when I try to change them to be 301 all the pages stop working and go to 404s.

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lbts,

    If you're getting 404's, then there MUST be something wrong with your mod_rewrite code.
    Code:
    RewriteEngine on
    # -FrontPage-
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName site.com
    AuthUserFile /home/sitecom/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/sitecom/public_html/_vti_pvt/service.grp
    RewriteCond %{HTTP_REFERER} !^http://www.site.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.site.com$    [NC]
    RewriteEngine on
    # Again? Remove this line
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?$ index.php?var1=$1&var2=$3&var5=$5 [L]
    # capture one or more letters and _'s in first atom, 
    # one or more letters, digits (except 0) and _'s in the third atom
    # and one or more digits in the fifth atom
    # with only the first atom required
    # and the third atom required for the fifth
    # with no trailing /
    # ANDed with the {HTTP_REFERER} RewriteCond statements
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z1-9_]+)(/([0-9]+))?)?/$ index.php?var1=$1&vae2=$3&var5=$5 [L]
    # Ditto the above EXCEPT requiring a trailing /
    # (BAD IDEA as it requires absolute links in the
    # index.php script or HTML's <base> directive)
    # AND is NOT subject to the
    # RewriteCond {HTTP_REFERER} statements
    The 301 would have told you what the redirection was TO and that should have given you an indication of the problem.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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