modrewrites (different rewrites but same destination - is this possible) ?

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

    #1

    modrewrites (different rewrites but same destination - is this possible) ?

    hi All,
    is it possible to do this?

    for instance:

    http://www.domain.com/pdisplay.php?p...igrav&type=htm
    to
    http://www.domain.com/ps2antigrav.html

    and

    http://www.domain.com/gdisplay.php?p...igrav&type=htm
    to
    http://www.domain.com/g2antigrav.html

    with a modrewrite:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([^/]+)\.html$ pdisplay.php?pa ge=p2/$1&type=htm
    RewriteRule ^([^/]+)\.html$ gdisplay.php?pa ge=g2/$1&type=htm

    it basically works for the first one but not the second? Anyone know
    why?
    cheers,
    Andrew

  • Marco Zilotti

    #2
    Re: modrewrites (different rewrites but same destination - is this possible) ?

    Because the first rule is always true -> the both url ends with .html

    you must add 1 more check in the rewrite rule, such as

    ps2(.*).html$ pdisplay.php?pa ge=p2/ps2$1&type=htm
    g2(.*).html$ gdisplay.php?pa ge=g2/g2$1&type=htm

    Marco

    Comment

    • Andrew

      #3
      Re: modrewrites (different rewrites but same destination - is this possible) ?

      hi Marco,
      thanks for replying, I'm a little confused as to what you mean by
      adding another a rewrite? I think I understand why the first rule is
      always true but where would I add that extra check in?

      RewriteRule ^([^/]+)\ps2(.*).html $ pdisplay.php?pa ge=p2/$1&type=htm

      cheers,
      Andrew

      Comment

      • Marco Zilotti

        #4
        Re: modrewrites (different rewrites but same destination - is this possible) ?

        no no, the rule

        RewriteRule ^([^/]+)\ps2(.*).html $ pdisplay.php?pa ge=p2/$1&type=htm

        is correct, because you have added the 'ps2' before (.*).html (that is
        '1 more check in the rewrite rule' of my previous post. Excuse me for
        my bad english, i'm italian :D )

        When apache look for a page, example
        http://www.domain.com/g2antigrav.html

        it find that both rules match :

        RewriteRule ^([^/]+)\.html$ pdisplay.php?pa ge=p2/$1&type=htm
        RewriteRule ^([^/]+)\.html$ gdisplay.php?pa ge=g2/$1&type=htm

        but the first rule is follow.

        In that rule
        RewriteRule ^([^/]+)\ps2(.*).html $ pdisplay.php?pa ge=p2/$1&type=htm

        http://www.domain.com/g2antigrav.html doesn't match, because the name
        of the page doesn't start with ps2, so the rule is ignored.

        with

        RewriteRule ^([^/]+)\g2(.*).html$ pdisplay.php?pa ge=g2/$1&type=htm

        the url http://www.domain.com/g2antigrav.html match because the name of
        the page starts with g2.

        Comment

        • Andrew

          #5
          Re: modrewrites (different rewrites but same destination - is this possible) ?

          hi Marco,
          thanks for your help but unfortunately that extra rule doesn't seem to
          work? I'm not sure how to fix the error? Any chance of lending another
          hand? :-)
          cheers
          Andrew

          Comment

          • Marco Zilotti

            #6
            Re: modrewrites (different rewrites but same destination - is this possible) ?

            mmm, test this rule:

            insert the .htaccess file in you root

            RewriteEngine On
            RewriteRule ^ps2(.*).html$ pdisplay.php?pa ge=p2/ps2$1&type=htm [L,NC]
            RewriteRule ^g2(.*).html$ gdisplay.php?pa ge=g2/g2$1&type=htm [L,NC]

            I use rules very similar in most of my website, and they work. Mmm, is
            the rewrite engine enabled ?

            Comment

            • Andrew

              #7
              Re: modrewrites (different rewrites but same destination - is this possible) ?

              hi Marco,
              thanks mate! It worked PERFECTLY!!!! :) Almost a month later and you
              solved my dilemma! Thankyou thankyou! Merry Christmas Marco!
              cheers,
              Andrew

              Comment

              • Marco Zilotti

                #8
                Re: modrewrites (different rewrites but same destination - is this possible) ?

                Perfect :D

                Comment

                Working...