Hi all,

Trying to get a grip on the nicely created url's.

From

http://www.mysite.com/index.php?id=220

to

http://www.mysite.com/220

is doable, done that for another one of my sties
but now I want to replace id=20 with the corresponding article title, like

http://www.mysite.com/this-would-be-the-title-of-220

Need some advice how to achieve this??

Tx

    Look up mod_rewrite for Apache.

      php has a function to check where it is being called from $_ENV['SCRIPT_URL']; just make cron copy index.php to all directories and then write a code such as

      <?php 
      $baselocation = "http://myhost/articles/";
      $doc = str_replace($baselocation, "", $_ENV['SCRIPT_URL']) . "./path to actual files");
      include ("../docs/". $doc);
      this should sort out your problem
      ?>
      

      so much for mod_rewrie :rolleyes:

        It looks like he's using a database...

          it does'nt matter if he's using a database just replace the include code for a mysql connect and query it should work the same way

            true but i like php
            I've even written my own subdomain handler in php

              Wow, nice. Could you post those few examples in Code Critique or PM them to me? I'd love to take a look at them.

                hi guys,

                With the help on a other forum I am playing with mod_rewrite.

                In a folder called testfolder I have

                # This .htaccess should sit beside the main index.php
                RewriteEngine on
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule (.*) index.php?$1 
                

                And in my testfolder

                $url = explode("/",$_SERVER['REQUEST_URI']);
                
                $title2 = str_replace("-"," ",$url[2]);
                

                And with $title2 I do the $query ..........title = '$title2'

                To- do list

                1 Now I need to think of all the special characters that can be part of a title and what to do with them.

                2 Need to get it in the form of

                http://www.mysite.com/article/this-would-be-the-title-of-220
                
                http://www.mysite.com/interview/this-would-be-the-title-of-220
                
                http://www.mysite.com/comments/this-would-be-the-title-of-220
                

                Right now I have it like
                http://www.mysite.com/index.php?page=article&id=220

                I'll keep you posted

                  That's not right....you need to set the the mod_rewrite engine to substitute something like: /comments/([A-Za-z0-9-]?) to index.php?title=$1

                  Now, your PHP script can explode($GET['title']), and not mess around with $SERVER stuff. The $_SERVER stuff was meant to be a substitution for mod_rewrite, not a companion.

                    logank do you want that subdomain script handler if so pm me ur mail and i'll send it 2 u

                      <?php
                      $this_URL = $HTTP_REFERER;
                      $pass1 = str_replace("http://", "", $this_URL);
                      $pass2 = explode(".", $pass1);
                      $subdomain = $pass2[0];
                      if (($subdomain != "www") && $subdomain != "")){
                          include($subdomain.".php"); // this will work as a header redirect as well but an include hides the fact it is not a real subdomain set in apache
                      }
                      ?>
                      Just add each subdomain to your hosts file
                      
                      
                        8 days later

                        Did you have any luck with the mod rewrite?

                        I am trying to do the same thing. My urls are .com/view.php?ItemID=17443

                        I want my urls to be view/page-title.html

                        Any Ideas? I read the apache mod_rewrite manual, very hard to understand.

                          Write a Reply...