I'm using WAMPSERVER on my laptop. I am trying to change my URL but it's sort of not working

This is what I have in my .htaccess file

#Turn on the rewrite engine
Options +FollowSymlinks
RewriteEngine on

#Request routing
RewriteRule ^([a-zA-Z0-9_-]*)/([a-zA-Z0-9_-]*)/([0-9]*)$	index.php?ID=$1&Code=$2&v=$3 [nc,qsa]

# Rewrite for GetSimDate.php?id=1&title=Title-Goes-Here
RewriteRule ^GetSimDate/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)$ GetSimDate.php?ID=$1&Code=$2 [NC,qsa]

RewriteRule ^UpdateSimDate/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)$ UpdateSimDate.php?ID=$1&Code=$2 [NC,qsa]

RewriteRule ^GetSimData/([0-9a-zA-Z_-]*)/([0-9a-zA-Z_-]*)$ GetSimData.php?ID=$1&Code=$2 [NC,qsa]

URL localhost/folder/GetSimDate/1212/3434 works however $_GET['ID'] does not show anything.

What is wrong?

    What does [font=monospace]$_GET[/font] contain?

    Keep in mind that rewrite rules are applied in the order you write them. What is that first one going to do and will the other three still match afterwards?

      #Turn on the rewrite engine
      #Options +FollowSymLinks
      RewriteEngine On
      
      #Request routing
      #RewriteRule ^GetSimDate/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ GetSimDate.php?ID=$1&Code=$2 [NC,L]
      
      #RewriteRule ^UpdateSimDate/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ UpdateSimDate.php?ID=$1&Code=$2 [NC,L]
      
      RewriteRule ^GetSimData/([0-9]+)$ GetSimData.php?ID=$1 [NC,L]
      

      Result:

      C:\wamp\www\MyGame\WS\Sim\GetSimData.php:5:
      array (size=0)
      empty

        Its wampsever, how can I check. My page display okay but I just can't get the variables from the url

          Mine is at C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf. Also, you should be able to get there by clicking on the Wampserver icon in the system tray when it's running, and select Apache -> httpd.conf.

          I don't know off-hand if it was enabled by default or I enabled it, but this looks like where it's turned on:

          <Directory "c:/wamp/www/">
              #
              # Possible values for the Options directive are "None", "All",
              # or any combination of:
              #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
              #
              # Note that "MultiViews" must be named *explicitly* --- "Options All"
              # doesn't give it to you.
              #
              # The Options directive is both complicated and important.  Please see
              # http://httpd.apache.org/docs/2.4/mod/core.html#options
              # for more information.
              #
              Options Indexes FollowSymLinks
          
          #
          # AllowOverride controls what directives may be placed in .htaccess files.
          # It can be "All", "None", or any combination of the keywords:
          #   AllowOverride FileInfo AuthConfig Limit
          #
          [B][COLOR="#B22222"]    AllowOverride all[/COLOR][/B]
          

            I noticed that you are not showing us the actual HTTP request url but rather just the file path on your machine that is supposed to be triggered:

            C:\wamp\www\MyGame\WS\Sim\GetSimData.php

            I can't help but wonder if www is your webroot or if MyGame is your web root. If you are requesting localhost/MyGame/GetSimData/WS/Sim then your mod_rewrite rules won't match because your urls start with MyGame and not GetSimData. The ^ char in your mod_rewrite rules matches the start of your request.

              I can't recall exactly, It's been a long time, but I think it depends on which folder you have our .htaccess file in. Is it in C:\wamp\www? Or is it in C:\wamp\www\MyGame?

              If your .htaccess is in C:\wamp\www\MyGame\WS\Sim then I think your rewrite rule would have to be a lot shorter. I still don't know exactly what url you are trying to access in your browser. The one you just posted, http://localhost/MyGame/WS/Sim/GetSimData.php, is just a straight url to the file and therefore doesn't match the rewrite rule at all. I'm guessing that a url you want to rewrite might look like http://localhost/MyGame/WS/Sim/GetSimData/1234. If that's the case, then the RewriteRule in your prior post should work if you put your .htaccess file in C:\wamp\www. If you put your rewrite rule in C:\wamp\www\MyGame\WS\Sim, then it's going to see urls that are a lot shorter so your .htaccess file has to be changed to something like this:

              RewriteRule ^GetSimData/([0-9]+)$ GetSimData.php?ID=$1 [NC,L]
              

              Getting mod_rewrite rules can be really frustrating. It can be tremendously helpful to set up logging and check the log file. See this:
              http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging

                That's a bit beyond me, how can I turn this on in simple terms?

                  NZ_Kiwis;11058755 wrote:

                  That's a bit beyond me, how can I turn this on in simple terms?

                  Seems to me you have two options:
                  1) Try to sort it out using trial and error with your .htaccess file. The key in this case is getting one rule that kind of works and then tweaking it gradually. This can be a real pain in the ass.
                  2) You can try and understand how to turn your mod_rewrite error logging on and then go inspect the results that you see in the log file which will give you more information about how Apache is reacting to your mod_rewrite rules.

                    Just food for thought for a somewhat different approach: in my little blog project, I just redirected everything (that wasn't going to /static) to the index.php file, where I then parsed the URI to figure out what the request was for.

                    .htaccess

                    DirectoryIndex index.php
                    <IfModule mod_rewrite.c>
                        RewriteEngine on
                        RewriteRule ^favicon static/favicon.ico
                        RewriteRule !^static index.php
                    </IfModule>
                    ErrorDocument 404 /static/404.html
                    

                    Applicable part of index.php:

                    $url = parse_url($_SERVER['REQUEST_URI']);
                    
                    if(!empty($url['query'])) {
                        parse_str($url['query'], $query);
                        array_merge($_GET, $query);
                    }
                    $action = strtolower(basename($url['path']));
                    if($action == '') {
                        $action = 'home';
                    }
                    

                    Then I have a switch() that chooses what to do based on some expected special values of $action, otherwise assuming $action refers to a specific post (which it looks for, or else returns a 404).

                      Based on NZ_kiwis posts, it's really hard to tell what is not working, but I think it has something to do with his code being in a subdirectory rather than the base of his web root. For him to understand what the problem is, it will be necessary for some focus and probably some trial and error.

                      On my workstation, the web root is /var/www/html. I create the contents of /var/www/html/.htaccess like so:

                      # route all requests to index.php so we can see what sort of match we're looking at
                      RewriteEngine on
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
                      RewriteRule ^(.*)$ index.php/$1 [L]
                      

                      And the file /var/www/html/index.php looks like this:

                      <?php
                      echo "this is " . __FILE__ . "</br>";
                      echo "<pre>";
                      echo $_SERVER["PATH_INFO"] . "</br>";
                      echo $_SERVER["PATH_TRANSLATED"] . "</br>";
                      echo $_SERVER["PHP_SELF"] . "</br>";
                      echo "</pre>";
                      

                      If I I use my browser to visit http://localhost/some/path/info, then this is the output I see in my browser:

                      this is /var/www/html/index.php
                      
                      /some/path/info
                      redirect:/index.php/some/path/info/path/info
                      /index.php/some/path/info
                      

                      Note how the entire path (/some/path/info) follows index.php in that last line. The $1 from my rewrite rule includes the entire path part of the url.

                      Now if I create a new subdir, /var/www/html/subdir, and I copy both index.php and .htaccess to that subdir:

                      cd /var/www/html
                      mkdir subdir
                      cp index.php subdir/index.php
                      cp .htaccess subdir/.htaccess
                      

                      And then I visit this slightly different url - http://localhost.com/subdir/some/path/info - then you should see that the request is being handled by subdir/index.php and that (EDIT) PHP_SELF changes a little but PATH_INFO and PATH_TRANSLATED don't:

                      this is /var/www/html/subdir/index.php
                      
                      /some/path/info
                      redirect:/index.php/some/path/info/path/info
                      /subdir/index.php/some/path/info
                      

                      More precisely, the $1 from my rewrite rule lacks the "subdir" part of the path. I'm not sure how to verbally describe this behavior of mod_rewrite and apache beyond saying that an .htaccess file's RewriteRule directive doesn't see the entire path when you put it in a subdirectory of the web root. Apache peels off the partial path that has resulted in the request being routed to the directory where this .htaccess file lives so the RewriteRule only sees the leftover part of the path.

                      Not really sure how to explain it beyond that. Subdirectories matter. Mod_rewrite is tricky. NZ_kiwis needs to be more specific about precisely where his files exist if he wants any helpful assistance. "subdir" gets shaved off from $1 when handled by the .htaccess file in the subdir directory.

                        Write a Reply...