2016-01-21 116 views
1

我得到了一个单独的PHP页面,需要显示不同的数据时,不同的网址输入或点击。动态内容页面未找到

所以我做的是创建一个content.php文件。

在该文件中,我把我的HTML和基本的东西(包括连接文件等),并添加以下查询:

//content 
$content    = "SELECT * FROM `db_content` WHERE alias = '".$_GET['alias']."' "; 
$contentcon   = $conn->query($content); 
$contentcr   = array(); 
while ($contentcr[] = $contentcon->fetch_array()); 

然后在我的.htaccess我添加以下行:

RewriteRule ^nieuw/(.*).html website/content.php?alias=$1 [L] 

因此,每个有nieuw/anytext.html的网址都应该到content.php并加载与别名匹配的数据。但是,当我输入该网址,我得到一个页面未找到错误。

有没有人看到我做错了什么?

回答

1

这个简单的设置工作。确保你启用了RewriteEngine。

.htaccess

# Enable rewriting. 
RewriteEngine on 

# Redirect nieuw to the content.php script 
RewriteRule ^nieuw/(.*).html$ website/content.php?alias=$1 [L] 

website/content.php(你可以用你的脚本替换这个,这个虚拟脚本,说明你的$_GET['alias']变量):

<?php 
echo $_GET['alias']; 
?> 

现在,当我访问nieuw/hallo_wereld.html我看的确hallo_wereld

+0

我已经在我的htaccess文件中添加了RewriteEngine on line。尽管如此,这些信息对于忘记/不知道它的人来说可能是有用的。 – twan

+0

好的,那么你的Apache日志文件究竟是什么?问题是否已解决? –