Anybody here know regex and redirect match?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Pheer
    So Fucking Banned
    • Dec 2002
    • 22083

    #1

    Anybody here know regex and redirect match?

    Holy shit it's not a political thread...

    Pretend we are working with something like this:
    domain.com/montana/milfs-in-bozeman.php
    domain.com/montana/bozeman-is-boring.php
    domain.com/montana/fuck-bozeman-it-sucks-here.php
    domain.com/montana/whatever-bozeman-random-shit.php

    And you want to redirect anything in the /montana/ folder that mentions bozeman to a new folder

    domain.com/montana/bozeman/index.php

    I dont need to match the filename in the new folder, I have plans for something different... just need to match the city and send it to the correct folder. Right now all the cities are just dumped in one folder... thousands of pages actually.

    Somebody have a htaccess code for this?
  • money biz
    Confirmed User
    • Jan 2003
    • 1017

    #2
    Not sure what you mean but I generate those types of pages and redirect using a cloaker

    Comment

    • Mr Pheer
      So Fucking Banned
      • Dec 2002
      • 22083

      #3
      Originally posted by money biz
      Not sure what you mean but I generate those types of pages and redirect using a cloaker
      Generating pages is easy and only takes seconds. Doing mass 301 redirects for pages that already have listings while maintaining SEO the correct way is more challenging.

      Comment

      • money biz
        Confirmed User
        • Jan 2003
        • 1017

        #4
        Only way I know is to import your pages into wordpress and use a cloaker plugin. Then redirect off keywords/searches anywhere you want.

        Comment

        • Mr Pheer
          So Fucking Banned
          • Dec 2002
          • 22083

          #5
          Originally posted by money biz
          Only way I know is to import your pages into wordpress and use a cloaker plugin. Then redirect off keywords/searches anywhere you want.
          Wordpress?

          OMG no...

          Comment

          • WiredGuy
            Pounding Googlebot
            • Aug 2002
            • 34512

            #6
            It's been a while since doing htaccess redirects, but you should be able to do a conditional match with regexp to match #domain.com/(.*?)/(.*?)bozeman(.*?)#

            WG
            Last edited by WiredGuy; 04-26-2018, 11:17 PM. Reason: updated string
            I play with Google.

            Comment

            • Mr Pheer
              So Fucking Banned
              • Dec 2002
              • 22083

              #7
              Originally posted by WiredGuy
              It's been a while since doing htaccess redirects, but you should be able to do a conditional match with regexp to match #domain.com/(.*?)/(.*?)bozeman(.*?)#

              WG
              Could you please type the whole thing?

              I can figure it out but it's like missing three digits of a phone number

              Comment

              • Bladewire
                StraightBro
                • Aug 2003
                • 56228

                #8
                You sneaky sneaky little mynx you


                Skype: CallTomNow

                Comment

                • EddyTheDog
                  Just Doing My Own Thing
                  • Jan 2011
                  • 25433

                  #9
                  Just the word 'regex' makes my head hurt - The guy that invented it must still laugh when he sees geeks tearing what little hair they have left out...

                  Comment

                  • blackmonsters
                    Making PHP work
                    • Nov 2002
                    • 20980

                    #10
                    [The correct answer has been blocked because Blackmonsters is on your shit list.]
                    Free Open Source Live Aggregated Cams Script (FOSLACS)

                    Comment

                    • Cyber Fucker
                      Hmm
                      • Sep 2005
                      • 12642

                      #11
                      There are many ways to achive that, one would be to place local .htaccess to /montana/ directory with the following lines:

                      Code:
                      <IfModule mod_rewrite.c>
                      RewriteEngine  on
                      RewriteCond %{REQUEST_URI} ^.*(bozeman).*$
                      RewriteRule ^ /montana/bozeman/index.php [L,R=302,NE]
                      </IfModule>

                      Comment

                      • Mr Pheer
                        So Fucking Banned
                        • Dec 2002
                        • 22083

                        #12
                        Originally posted by blackmonsters
                        [The correct answer has been blocked because Blackmonsters is on your shit list.]
                        Since when?

                        Comment

                        • Mr Pheer
                          So Fucking Banned
                          • Dec 2002
                          • 22083

                          #13
                          Originally posted by Cyber Fucker
                          There are many ways to achive that, one would be to place local .htaccess to /montana/ directory with the following lines:

                          Code:
                          <IfModule mod_rewrite.c>
                          RewriteEngine  on
                          RewriteCond %{REQUEST_URI} ^.*(bozeman).*$
                          RewriteRule ^ /montana/bozeman/index.php [L,R=302,NE]
                          </IfModule>
                          This almost works but it gives me some weird redirect loop

                          Comment

                          • Mr Pheer
                            So Fucking Banned
                            • Dec 2002
                            • 22083

                            #14
                            I'm just deleting it and rebuilding it. Spent too much time on it already, and google will respider the whole thing in a couple of days. No big deal.

                            Comment

                            • Cyber Fucker
                              Hmm
                              • Sep 2005
                              • 12642

                              #15
                              Originally posted by Mr Pheer
                              This almost works but it gives me some weird redirect loop
                              Yup, could be, cause the url redirected to also contains the "bozeman" keyword.

                              So, you can add some condition before to ignore the url you are redirecting to for example:


                              Code:
                              <IfModule mod_rewrite.c>
                              RewriteEngine  on
                              RewriteCond %{REQUEST_URI} !^.*(\/montana\/bozeman\/index.php)$
                              RewriteCond %{REQUEST_URI} ^.*(bozeman).*$
                              RewriteRule ^ /montana/bozeman/index.php [L,R=302,NE]
                              </IfModule>

                              Comment

                              • Mr Pheer
                                So Fucking Banned
                                • Dec 2002
                                • 22083

                                #16
                                Originally posted by Cyber Fucker
                                Yup, could be, cause the url redirected to also contains the "bozeman" keyword.

                                So, you can add some condition before to ignore the url you are redirecting to for example:


                                Code:
                                <IfModule mod_rewrite.c>
                                RewriteEngine  on
                                RewriteCond %{REQUEST_URI} !^.*(\/montana\/bozeman\/index.php)$
                                RewriteCond %{REQUEST_URI} ^.*(bozeman).*$
                                RewriteRule ^ /montana/bozeman/index.php [L,R=302,NE]
                                </IfModule>
                                Thanks, I will try this out and let you know if it works. Luckily I got distracted earlier and havent deleted it yet

                                Comment

                                • Mr Pheer
                                  So Fucking Banned
                                  • Dec 2002
                                  • 22083

                                  #17
                                  That worked great

                                  Thanks, Cyber Fucker!

                                  Comment

                                  Working...