mod rewrite

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Slaughter

    mod rewrite

    How the heck do I get mod rewrite to add extensions to any file?

    RewriteRule ^(.*)$ $1\.php [nc]

    To me that should find any group of characters(such as any path) and then
    add the .php to the end? But this doesn't work and gives me a server error.
    If I remove the $ in front of the 1 then it does but ofcourse all my links
    end up as 1.php

    I can also do something like

    RewriteRule ^3(.*)$ $1\.php [nc]

    and all my links will be redirected to 3---.php

    What I want is to take

    [url] into [url].php

    (without query string and or other special chars such as ([^&?]&) or [QSA])


    I just can't understand why the following does not work ;/

    RewriteRule ^(.*)$ $1\.php [nc]

    $1 should be whatever is matched by (.*)? (which should be the whole url?)
    In any case I can't see how its an error?

    Thanks,
    Jon



  • Jerry Stuckle

    #2
    Re: mod rewrite

    Jon Slaughter wrote:
    How the heck do I get mod rewrite to add extensions to any file?
    >
    RewriteRule ^(.*)$ $1\.php [nc]
    >
    To me that should find any group of characters(such as any path) and then
    add the .php to the end? But this doesn't work and gives me a server error.
    If I remove the $ in front of the 1 then it does but ofcourse all my links
    end up as 1.php
    >
    I can also do something like
    >
    RewriteRule ^3(.*)$ $1\.php [nc]
    >
    and all my links will be redirected to 3---.php
    >
    What I want is to take
    >
    [url] into [url].php
    >
    (without query string and or other special chars such as ([^&?]&) or [QSA])
    >
    >
    I just can't understand why the following does not work ;/
    >
    RewriteRule ^(.*)$ $1\.php [nc]
    >
    $1 should be whatever is matched by (.*)? (which should be the whole url?)
    In any case I can't see how its an error?
    >
    Thanks,
    Jon
    >
    >
    >
    Jon,

    Try alt.apache.conf iguration - where they specialize in these questions.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Schraalhans Keukenmeester

      #3
      Re: mod rewrite

      On Wed, 02 May 2007 22:15:18 -0500, Jon Slaughter wrote:
      How the heck do I get mod rewrite to add extensions to any file?
      >
      RewriteRule ^(.*)$ $1\.php [nc]
      >
      To me that should find any group of characters(such as any path) and then
      add the .php to the end? But this doesn't work and gives me a server error.
      If I remove the $ in front of the 1 then it does but ofcourse all my links
      end up as 1.php
      >
      I can also do something like
      >
      RewriteRule ^3(.*)$ $1\.php [nc]
      >
      and all my links will be redirected to 3---.php
      >
      What I want is to take
      >
      [url] into [url].php
      >
      (without query string and or other special chars such as ([^&?]&) or [QSA])
      >
      >
      I just can't understand why the following does not work ;/
      >
      RewriteRule ^(.*)$ $1\.php [nc]
      >
      $1 should be whatever is matched by (.*)? (which should be the whole url?)
      In any case I can't see how its an error?
      >
      Thanks,
      Jon
      http://www.workingwith .me.uk/articles/scripting/mod_rewrite will probably
      help you get to grips with mod_rewrite, at least it scratches the surface
      of what's possible.

      Sh.

      Comment

      • Jon Slaughter

        #4
        Re: mod rewrite


        "Schraalhan s Keukenmeester" <invalid@invali d.spamwrote in message
        news:pan.2007.0 5.03.07.09.47.5 7787@invalid.sp am...
        On Wed, 02 May 2007 22:15:18 -0500, Jon Slaughter wrote:
        >
        >How the heck do I get mod rewrite to add extensions to any file?
        >>
        >RewriteRule ^(.*)$ $1\.php [nc]
        >>
        >To me that should find any group of characters(such as any path) and then
        >add the .php to the end? But this doesn't work and gives me a server
        >error.
        >If I remove the $ in front of the 1 then it does but ofcourse all my
        >links
        >end up as 1.php
        >>
        >I can also do something like
        >>
        >RewriteRule ^3(.*)$ $1\.php [nc]
        >>
        >and all my links will be redirected to 3---.php
        >>
        >What I want is to take
        >>
        >[url] into [url].php
        >>
        >(without query string and or other special chars such as ([^&?]&) or
        >[QSA])
        >>
        >>
        >I just can't understand why the following does not work ;/
        >>
        >RewriteRule ^(.*)$ $1\.php [nc]
        >>
        >$1 should be whatever is matched by (.*)? (which should be the whole
        >url?)
        >In any case I can't see how its an error?
        >>
        >Thanks,
        >Jon
        >
        http://www.workingwith .me.uk/articles/scripting/mod_rewrite will probably
        help you get to grips with mod_rewrite, at least it scratches the surface
        of what's possible.
        >
        Yeah, I've seen that site... but there seems to be something wrong with my
        code that isn't explained on such basic sites

        RewriteRule ^(.*)$ 1\.php [nc]

        works fine for what its does but I cannot refer to the group (.*) using $1
        like I am suppose to be. If the pattern is not so general then it works...
        it acts like its not matching correctly.



        Comment

        • Chung Leong

          #5
          Re: mod rewrite

          On May 3, 5:15 am, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
          How the heck do I get mod rewrite to add extensions to any file?
          >
          RewriteRule ^(.*)$ $1\.php [nc]
          >
          To me that should find any group of characters(such as any path) and then
          add the .php to the end? But this doesn't work and gives me a server error.
          If I remove the $ in front of the 1 then it does but ofcourse all my links
          end up as 1.php
          >
          I can also do something like
          >
          RewriteRule ^3(.*)$ $1\.php [nc]
          >
          and all my links will be redirected to 3---.php
          >
          What I want is to take
          >
          [url] into [url].php
          >
          (without query string and or other special chars such as ([^&?]&) or [QSA])
          >
          I just can't understand why the following does not work ;/
          >
          RewriteRule ^(.*)$ $1\.php [nc]
          >
          $1 should be whatever is matched by (.*)? (which should be the whole url?)
          In any case I can't see how its an error?
          >
          Thanks,
          Jon
          Why the n flag? That's what's causing the server error, I think.

          Comment

          • Jon Slaughter

            #6
            Re: mod rewrite


            "Chung Leong" <chernyshevsky@ hotmail.comwrot e in message
            news:1178185075 .511221.175380@ y5g2000hsa.goog legroups.com...
            On May 3, 5:15 am, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
            >How the heck do I get mod rewrite to add extensions to any file?
            >>
            >RewriteRule ^(.*)$ $1\.php [nc]
            >>
            >To me that should find any group of characters(such as any path) and then
            >add the .php to the end? But this doesn't work and gives me a server
            >error.
            >If I remove the $ in front of the 1 then it does but ofcourse all my
            >links
            >end up as 1.php
            >>
            >I can also do something like
            >>
            >RewriteRule ^3(.*)$ $1\.php [nc]
            >>
            >and all my links will be redirected to 3---.php
            >>
            >What I want is to take
            >>
            >[url] into [url].php
            >>
            >(without query string and or other special chars such as ([^&?]&) or
            >[QSA])
            >>
            >I just can't understand why the following does not work ;/
            >>
            >RewriteRule ^(.*)$ $1\.php [nc]
            >>
            >$1 should be whatever is matched by (.*)? (which should be the whole
            >url?)
            >In any case I can't see how its an error?
            >>
            >Thanks,
            >Jon
            >
            Why the n flag? That's what's causing the server error, I think.
            >
            no
            means no case. wasn't working because of recursion I guess,

            #RewriteCond %{REQUEST_URI} !\.php$

            RewriteRule ^(.*)[/]$ /Index.php\?$1/Main.php



            essentially works but need to par it down to only work in specific cases





            Comment

            • Toby A Inkster

              #7
              Re: mod rewrite

              Jon Slaughter wrote:
              RewriteRule ^(.*)[/]$ /Index.php\?$1/Main.php
              >
              essentially works but need to par it down to only work in specific cases
              RewriteRule ^(case1|case2|c ase3)[/]$ /Index.php\?$1/Main.php

              --
              Toby A Inkster BSc (Hons) ARCS
              Fast withdrawal casino UK 2025 – Play now & cash out instantly! Discover the top sites for rapid, secure payouts with no delays.

              Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux

              Comment

              Working...