删除“index.php?page = filename”

时间:2011-05-19 14:01:12

标签: .htaccess

我希望我的网站看起来像这样: http://www.example.com/about而不是web_url / index [dot] php?page = about

在我的索引[dot] php中,我的导航链接如下:

<a href="index[dot]php?page=about">about</a>
etc.
...
$view = $_GET['page'];
switch($view){
 case 'about':
 include("pages/about.html");
 break;

 case 'project':
 include("pages/project.html");
 break;

... and so on
}

/* I have tried edit .htaccess file */
like this:
order allow,deny
allow from all


Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ websiteurl/$1 [R=301,L]

请帮忙!

谢谢, 别名

2 个答案:

答案 0 :(得分:0)

这就是我的所作所为:

RewriteEngine  on
RewriteRule    ^[^/.]*$  /run.php [L]

然后我有一个文件run.php来计算全局变量的文件路径:

 $basename = $_SERVER['REDIRECT_URL'];
 $basename = ereg_replace('.*/', '', $basename);
 $basename = ereg_replace('\.html$', '', $basename);
 if($basename == '') {
     $basename = 'index';
 }

 $html_file = "$basename.html";
 $php_file = "$basename.php";

然后你可以把它包括在内,无论你做什么,都把它作为模板阅读。

答案 1 :(得分:0)

试试这个:

$view = $_SERVER[REQUEST_URI];
switch($view){
 case 'about':
 include("pages/about.html");
 break;
...
}

$ _ SERVER [REQUEST_URI]将在http主机url之后获取URI段,因此

www.example.com/uri -> $_SERVER[REQUEST_URI] == "uri"