开发者

How can I go back to showing the content of /index.php?

开发者 https://www.devze.com 2023-03-24 10:58 出处:网络
Here\'s part of my .htaccess file: .htaccess: RewriteRule ^([a-z0-9A-Z_-]+)$ /article/index.php?title=$1 [L]

Here's part of my .htaccess file:

.htaccess:

RewriteRule ^([a-z0-9A-Z_-]+)$ /article/index.php?title=$1 [L]

But the problem is that when title is empty it doesn't show me the content of http://www.domain.com/index.php. I can't even link to http://www.domain.com/ anymore without throwing the error.

PHP: http://www.domain.com/article/index.php

开发者_如何学编程
<?php

if(!empty($_GET['title']))
{
    $a = mysql_query("SELECT * FROM `articles` WHERE `title` = '".mysql_real_escape_string($_GET['title'])."'");
}
else
{
    $a = mysql_query("SELECT * FROM `articles` WHERE `id` = '".mysql_real_escape_string($_GET['id'])."'");
}

$b = mysql_fetch_assoc($a) or mysql_error();

?>


You pretty much have 2 choices:

1. Use this rule: If home page is hit, then title parameter will be empty (so you have to handle this moment somehow -- adjust your PHP code accordingly).

RewriteRule ^([a-z0-9A-Z_-]*)$ /article/index.php?title=$1 [QSA,L]

2. Use specific rule for home page/website root hit (add it before your current rule):

RewriteRule ^$ /article/index.php?title=home [QSA,L]

The title=home means it's a hit for website root (you can change home to whatever you want).

0

精彩评论

暂无评论...
验证码 换一张
取 消