Im doing a website for a school project and I was looking into using cleanURL so I followed this tutorial www. you tube.com/watch?v=ZgCW2x5QCXo, when i put /studytips/home it works perfectly fine but if i add a / or something it stops working. Images of what happensWithout the /foo With the /foo I will include his class, to use it i do the following:
if($url->segment(1)){
$s1=($url->segment(1));
if((file_exists("includes/$s1.php"))){
include("includes/$s1.php");
} else {
include("includes/404.php");
}
}else include("includes/home.php");
i came up with the hadling of it not sure if it is the best approach^
class simpleUrl{
var $site_path;
function __construct($site_path){
$this->site_path= $this->removeSlash($site_path);
}
function __toString(){
return $this->site_path;
}
private function removeSlash($string){
if( $string[strlen($string)-1] == '/')
$string =rtrim($string,'/');
return $string;
}
function segment($segment){
$url = str_replace($this->site_path,'' , $_SERVER['REQUEST_URI']);
$url = explode('/',$url);
if(isset($url[$segment]) )
return $url[$segment];
return $url;
}
}
htaccess file:
<IfModule mod_rewrite.c> RewriteEngine On
RewriteBase /copy/studytips/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
</IfModule>
You can use in your .htaccess
:
RewriteEngine On
RewriteBase /copy/studytips/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php/$1
Which works with or without /
, but in any case returns the /
in de rewrite url.