PHP Classes
elePHPant
Icontem

Removing the slug part of a url

Recommend this page to a friend!

      PHP Screenshot URL Handler  >  All threads  >  Removing the slug part of a url  >  (Un) Subscribe thread alerts  
Subject:Removing the slug part of a url
Summary:Change url text
Messages:4
Author:Alex Evans
Date:2018-02-08 23:56:36
 

  1. Removing the slug part of a url   Reply   Report abuse  
Alex Evans - 2018-02-08 23:56:36
I want the page name to be removed from a URL on my website once the visitor arrives to it through a menu link in my website.

For example : http://www.beleuramyhome.org.au/frontpage.php
To show only as : http://www.beleuramyhome.org.au/

I tried several things with .htaccess, but they either locked the site or didn't do anything.

I know that when I visit the site through an Android device or an Apple device it does it by itself.... Windows PC don't....

I need some help please

Thanks

  2. Re: Removing the slug part of a url   Reply   Report abuse  
Malik umer Farooq - 2018-02-09 01:44:02 - In reply to message 1 from Alex Evans
its not to much difficult first of all if your web struct is MVC then its easy by mvc you can easily do that
example
For example : http://www.beleuramyhome.org.au/frontpage.php
show : http://www.beleuramyhome.org.au/

another example
For example : http://www.beleuramyhome.org.au/profile?username=malik
show : http://www.beleuramyhome.org.au/profile/malik
thats it

your htaccess file look like that
```Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /your directory if project root just / /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [L,QSA]


</IfModule>```
you can handel every thing form index.php in public folder
now what next create folder app inside root of project then create App.php look like that you can change as you want
```Class App
{
protected $controller = 'home';
protected $method = 'index';
protected $params = [];

public function __construct(){

$url = $this->parseurl();

if(file_exists('../app/controllers/'.$url[0]. '.php'))
{
$this->controller = $url[0];
unset($url[0]);
}
require_once "../app/controllers/".$this->controller .".php";
$this->controller = new $this->controller;

if(isset($url[1])){
if(method_exists($this->controller, $url[1])){
$this->method = $url[1];
unset($url[1]);
}
}
$this->params = $url ? array_values($url) : [];
call_user_func_array([$this->controller,$this->method],$this->params);


}

public function parseurl(){
if(isset($_GET['url'])){
return $url = explode('/',filter_var(rtrim($_GET['url'] , '/') , FILTER_SANITIZE_URL) );
}

}
} Class App
{
protected $controller = 'home';
protected $method = 'index';
protected $params = [];

public function __construct(){

$url = $this->parseurl();

if(file_exists('../app/controllers/'.$url[0]. '.php'))
{
$this->controller = $url[0];
unset($url[0]);
}
require_once "../app/controllers/".$this->controller .".php";
$this->controller = new $this->controller;

if(isset($url[1])){
if(method_exists($this->controller, $url[1])){
$this->method = $url[1];
unset($url[1]);
}
}
$this->params = $url ? array_values($url) : [];
call_user_func_array([$this->controller,$this->method],$this->params);


}

public function parseurl(){
if(isset($_GET['url'])){
return $url = explode('/',filter_var(rtrim($_GET['url'] , '/') , FILTER_SANITIZE_URL) );
}

}
} ```
now create controller.php
```class Controller
{
public function model($folder,$model)
{
if(file_exists("../app/models/".$folder . "/". $model.".php")){
require_once "../app/models/".$folder . "/". $model.".php";
return new $model();
}else{
require_once "../app/errors/pages/index.php";
}
}
public function view($theme,$view, $parms = [] , $data = [] , $lang = [] )
{
if(file_exists("../app/view/theme/". $theme ."/" . $view.".php")){
require_once "../app/view/theme/". $theme ."/" . $view.".php";
}else{
require_once "../app/errors/pages/index.php";
}
}}```
now include those file in init.php and create index.php in public directory and include the file init then create controllers folder then create home.php
```
class Home extends Controller{

public function index()
{
echo "hay i am home"
}
}
now browse your website you only need http://www.beleuramyhome.org.au/ if you create login controller then http://www.beleuramyhome.org.au/login thats it
if you not understand i am ready for your help put your code in bitbucket as its provide private repo system and add me memeber i help you thanks

  3. Re: Removing the slug part of a url   Reply   Report abuse  
Alex Evans - 2018-02-09 08:38:24 - In reply to message 2 from Malik umer Farooq
Hi Malik,

Thank you so much for trying to help me, but I am new to this.
I tried the following in my .htaccess file. I uploaded the file as ASCII into the web root whic is /public_html
The home page for the site is frontpage.php - the following is my code, but it does not work

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /public_html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ frontpage.php?url=$1 [L,QSA]

</IfModule>

I do not understand your code in php and have no idea how to implement it and what is bitbucket ?

Thaks again
Alex

  4. Re: Removing the slug part of a url   Reply   Report abuse  
Malik umer Farooq - 2018-02-09 14:35:35 - In reply to message 2 from Malik umer Farooq
what is bitbucket ?
Bitbucket is a web-based version control repository hosting service owned by Atlassian, for source code and development projects that use either Mercurial (since launch) or Git (since October 2011[2]) revision control systems. Bitbucket offers both commercial plans and free accounts. It offers free accounts with an unlimited number of private repositories (which can have up to five users in the case of free accounts) as of September 2010. Bitbucket integrates with other Atlassian software like Jira, HipChat, Confluence and Bamboo.
How to use bitbucet?
follow
bitbucket.org/tutorials/bucket-o-sa ...
is you php file in public_html same as htaccess?
why you can write index.php file and handel that?
what error is show when you try yourweb/frontpage ?
if you need more help you can also message me privatelly as its realtime https://www.facebook.com/malik786313\
Thanks