Jump to content
php.lv forumi

RewriteBase dinamiski?


ezis

Recommended Posts

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|png|js|jpg|gif|jpeg|avi|mp3)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]

 

Šito iemet lapas galvenajā failā

Saliec masīvā kuras lapas tu vēlies, lai darbojas lapā, respektīvi tev viņš pārveidos uz http://domain.lv/login/ vai /directory/

$allowed_site_pages = array(
   	'directory',
   	'login',
);

 

Un arī šito

 

$model_to_load  = 'dashboard'; // Default site page
$model_requested  = '';

if( isset( $_GET['p'] ) AND !empty( $_GET['p'] ) )
{
$params = explode( '/', $_GET['p'] );
$model_requested  = strtolower( $params[0] );
}
if( !empty( $model_requested ) AND in_array( $model_requested, array_keys( $allowed_site_pages ) ) )
{
$model_to_load = $model_requested;
}
else
{
$model_requested = $model_to_load;
}

 

Pēdējais valsis

 

if( !file_exists( '/pages/' . $model_to_load . '.php' ) )
{
$model_to_load = '404';
}

ob_start();

include '/pages/' . $model_to_load . '.php';

ob_end_flush();

 

Tas būtībā ir viss, ceru ka saprati.

Kaspars.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...