Em có tham khảo một số bài ở mấy web forum trên mạng về cách Rewrite Link trong phần index ( .htacess thì rewrite vào đó thì nó lại dài dòng, lỡ nén zip mất file này thì viết ít lại cũng đỡ)
//code index.php
define( 'INCLUDE_DIR', dirname( __FILE__ ) . '/inc/' );
$rules = array(
'picture' => "/picture/(?'text'[^/]+)/(?'id'\d+)", // '/picture/some-text/51'
'album' => "/album/(?'album'[\w\-]+)", // '/album/album-slug'
'category' => "/category/(?'category'[\w\-]+)", // '/category/category-slug'
'page' => "/page/(?'page'about|contact)", // '/page/about', '/page/contact'
'post' => "/(?'post'[\w\-]+)", // '/post-slug'
'home' => "/" // '/'
);
$uri = rtrim( dirname($_SERVER["SCRIPT_NAME"]), '/' );
$uri = '/' . trim( str_replace( $uri, '', $_SERVER['REQUEST_URI'] ), '/' );
$uri = urldecode( $uri );
foreach ( $rules as $action => $rule ) {
if ( preg_match( '~^'.$rule.'$~i', $uri, $params ) ) {
include( INCLUDE_DIR . $action . '.php' );
exit();
}
}
include( INCLUDE_DIR . '404.php' );
// .htaccess
RewriteEngine On
RewriteRule ^inc/.*$ index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
LÀM THẾ NÀO ĐỂ SỬ DỤNG $GET trong
file INC/post.php ( Có Rewrite url ở trên )
Bình thường thì localhost/inc/post.php?slug=aaa ( Thì nó nhận $GET = 'slug' )
Sau khi xài code trên thì nó không nhận $GET nữa là sao nhỉ :(
Giờ làm thế nào để nó nhận $GET ạ