如何使用.htaccess和php制作用户友好的URL

时间:2015-03-04 06:36:18

标签: php .htaccess friendly-url

嗨朋友我是php新手,请帮助我如何制作我的php网站的seo友好网址, 动态链接为:http://watchfullmovie1.com/pk/software_detail.php?mcat=windows&catid=downloaders&slug=internet_download_manager_idm_2

如何使用.htaccess

制作友好网址

这是我到目前为止所做的,但它不起作用:

## RewriteRule ^(.+)/(.+)$ /software_detail.php?slug=$1&mcat=$2 [NC,L]

1 个答案:

答案 0 :(得分:1)

我认为你想要做的是允许漂亮的网址:

http://domain.com/movie/windows/internet/idm2

.htaccess文件:

RewriteEngine On

# This will send all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^\.]*[^/]$ index.php  [L]

index.php文件:

<?php
// parse incoming url and decide what to do
$paths=explode("/", $_SERVER['REQUEST_URI']);
// $paths[1] == "movie"
// $paths[0] == "windows"

// now you can decide what to do:
switch( $paths[1] ){
   case 'movie':
         ...
         break;
   case 'something_else':
         ...
         break;
   default:
         ...
 }