.Htaccess/Mod_Rewrite ninjas inside plz.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killswitch - BANNED FOR LIFE
    • Jul 2026

    #1

    .Htaccess/Mod_Rewrite ninjas inside plz.

    Ok, I am doing a simple domain.com to www.domain.com redirect, and it works fine, but if you go to domain.com/somepage.html it redirects to www.domain.com/ instead of www.domain.com/somepage.html.

    Anyone know why? And how to fix it?

    Code:
    <IfModule mod_rewrite.c>
    
      RewriteEngine On
    
      Options +FollowSymLinks
      Options +Indexes
    
      ErrorDocument 404 /
    
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . / [L]
    
      RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
      RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
    
    </IfModule>
    Last edited by Guest; 11-15-2009, 06:51 PM.
  • alias
    aliasx
    • Apr 2001
    • 19010

    #2
    Try a full document url for the 404 /

    eg:

    ErrorDocument 404 /404.html

    or you could use a full url
    ErrorDocument 404 http://www.someserver.com/404.html
    https://porncorporation.com

    Comment

    • JamesK
      hi
      • Jun 2002
      • 16731

      #3
      This is my non-www to www redirection code. Might be of use.

      Code:
      #WWW Redirect
      RewriteBase /
      RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
      RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
      M3Server - NATS Hosting

      Comment

      • Killswitch - BANNED FOR LIFE

        #4
        Originally posted by alias
        Try a full document url for the 404 /

        eg:

        ErrorDocument 404 /404.html

        or you could use a full url
        ErrorDocument 404 http://www.someserver.com/404.html
        ErrorDocument doesn't effect it, it's the WWW redirection that isn't working properly or something.

        Originally posted by JamesK
        This is my non-www to www redirection code. Might be of use.

        Code:
        #WWW Redirect
        RewriteBase /
        RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
        RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
        Mine is the same as yours, except I use regex in mine so I don't have to edit it and can just upload the same .htaccess file to any new site I create without editing anything, which is what I want, since my framework doesn't need anything different. Works for any domain with .com/net/org.

        Comment

        • Killswitch - BANNED FOR LIFE

          #5
          Edit: Scratch that...
          Last edited by Guest; 11-15-2009, 07:14 PM.

          Comment

          • alias
            aliasx
            • Apr 2001
            • 19010

            #6
            You added ! then $ and it worked? cool!$
            https://porncorporation.com

            Comment

            • Killswitch - BANNED FOR LIFE

              #7
              Gah, still not fucking working.

              Comment

              • alias
                aliasx
                • Apr 2001
                • 19010

                #8
                Bump, I tried to help. No luck, Kill says he has mod rewrite active. This didn't work:

                RewriteCond %{HTTP_HOST} !^www.dom.com$ [NC]
                RewriteRule ^(.*)$ http://www.dom.com/$1 [R,L]
                https://porncorporation.com

                Comment

                • Killswitch - BANNED FOR LIFE

                  #9
                  It's redirecting the domain properly, but during the redirection, it's killing any actual directory and or pages you have after it.

                  Comment

                  • mikeyddddd
                    Viva la vulva!
                    • Mar 2003
                    • 16557

                    #10
                    This is what I use:

                    Code:
                    RewriteEngine On 
                    RewriteCond %{HTTP_HOST} !^www\.mikeyddddd\.com$ [NC]
                    Rewriterule (.*) http://www.mikeyddddd.com/$1 [R=301]

                    Comment

                    • borked
                      Totally Borked
                      • Feb 2005
                      • 6284

                      #11
                      and to add my , this is what I use:

                      Code:
                      RewriteEngine on
                      rewritecond %{http_host} ^domain\.com [nc]
                      rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc,L]
                      edit - to add mine's different than the others' above, cos I *only* want to rewrite domain.com->www.domain.com
                      hence the ^domain.com
                      the others use !^www.domain.com
                      which would rewrite subdomain.domain.com which I can't have
                      Last edited by borked; 11-15-2009, 10:29 PM.

                      For coding work - hit me up on andy // borkedcoder // com
                      (consider figuring out the email as test #1)



                      All models are wrong, but some are useful. George E.P. Box. p202

                      Comment

                      • mmcfadden
                        So Fucking Banned
                        • Oct 2008
                        • 5099

                        #12
                        and I will just post so I can find this thread later

                        Comment

                        • fris
                          I have to go potty
                          • Aug 2002
                          • 55726

                          #13
                          try this

                          Code:
                          RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
                          RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]
                          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                          My Latest Theme

                          Comment

                          • fris
                            I have to go potty
                            • Aug 2002
                            • 55726

                            #14
                            should be this actually

                            Code:
                            RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org)) [NC]
                            RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]
                            Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                            My Latest Theme

                            Comment

                            • fris
                              I have to go potty
                              • Aug 2002
                              • 55726

                              #15
                              also try this one

                              Code:
                              RewriteEngine On
                              RewriteCond %{HTTP_HOST} !^www\.
                              RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
                              Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                              My Latest Theme

                              Comment

                              • JamesK
                                hi
                                • Jun 2002
                                • 16731

                                #16
                                fris to the rescue
                                M3Server - NATS Hosting

                                Comment

                                • Killswitch - BANNED FOR LIFE

                                  #17
                                  Neither work still, no fucking clue wtf is going on, I'll have to talk to tech at AmeriNOC maybe something with the server I'm on.

                                  Comment

                                  • Doctor Feelgood
                                    Confirmed User
                                    • Nov 2005
                                    • 2112

                                    #18
                                    all of yous are wrong, this is what he wants

                                    Code:
                                    rewritecond %{HTTP_HOST} ^yoursite\.com 
                                    RewriteRule ^(.*) http://www.yoursite.com/$1 [L,R=301]

                                    Comment

                                    • fris
                                      I have to go potty
                                      • Aug 2002
                                      • 55726

                                      #19
                                      Originally posted by Doctor Feelgood
                                      all of yous are wrong, this is what he wants

                                      Code:
                                      rewritecond %{HTTP_HOST} ^yoursite\.com 
                                      RewriteRule ^(.*) http://www.yoursite.com/$1 [L,R=301]
                                      ya he wants it so he can place in any domain without editing each .htaccess
                                      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                                      My Latest Theme

                                      Comment

                                      • Killswitch - BANNED FOR LIFE

                                        #20
                                        Thanks for everyones help, but I finally after giving it another whirl today, got it.

                                        Problem? I put the code just below RewriteBase /

                                        Code:
                                        <IfModule mod_rewrite.c>
                                        
                                          RewriteEngine On
                                        
                                          Options +FollowSymLinks
                                          Options +Indexes
                                        
                                          ErrorDocument 404 /
                                        
                                          RewriteBase /
                                          RewriteCond %{HTTP_HOST} ^([^.]+\.(com|net|org))$ [NC]
                                          RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
                                        
                                          RewriteCond %{REQUEST_FILENAME} !-f
                                          RewriteCond %{REQUEST_FILENAME} !-d
                                          RewriteRule . / [L]
                                        
                                        </IfModule>

                                        Comment

                                        • Robocrop
                                          Confirmed User
                                          • Aug 2008
                                          • 2785

                                          #21
                                          Hows your Tube script turning out btw?

                                          Comment

                                          Working...