2017-09-22 82 views
2

请帮我解决这个问题。我一直在努力与htaccess一段时间。 我有一个链接索引页beedy.php必须传递一些参数,如htaccess重写规则显示错误

<a href=”beedy.php?user=1”>Link 1</a> 

,但我不希望它展现给用户,所以我写了这样的 链接1 用户价值是1这里 哪些工作正常。但在beedy.php页面上,我有另一个链接,应该带我到我们的页面。但是,当我点击链接时显示的页面未找到(请求的URL/mvc/bd/bolade/1/seeOtherLink/About /在此服务器上找不到)。 我搜索了谷歌,但没有一个足够说明问题。

我的项目是这样构造的。 的mvc - > BD-> MVC的是该项目的父文件夹,而BD是我有我的

工作index.php页面如下

<html> 
<head> <title>Hey</title></head> 
<body> 
<h1 > THIS IS HOME PAGE </h1> 
<a href="bolade/1/"> Link 1 </a> 
<br /> 
<a href="bolade/2/">Link 2</a> 

</body> 
</html> 

我有其他文件我的.htaccess文件结构像这样

<IfModule mod_rewrite.c> 
RewriteEngine On  
#RewriteBase/

#Rewrite beedy URLs 
# Input: user/NAME/ 
# Output: beedy.php?id=userId 
RewriteRule ^bolade/(\w+)/?$ beedy.php?user=$1 [L] 

#this should take me to about page, or any page that starts with seeOtherLink/ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^seeOtherLink /(\w+)$ $1.php  

</IfModule> 

Beedy.php页面如下

<html> 
<head><title>Hey Beedy</title></head> 
<body> 
<a href="seeOtherLink/About/"> Go to About Us</a> 
<br /> 
<a href="seeOtherLink/Contact/"> Go to Contact Us</a> 
<br /> 

<?php 
$id = $_GET['user']; 
switch($id){ 
case 1: 
echo "This is the First value"; 
break; 
case 2: 
echo "This is the Second value"; 
break; 
} 
?> 

</body> 
</html> 
+0

尝试删除您的网址中的空格 –

+0

我做了,但结果仍然相同 –

回答

1

Beedy.php页面,你在按钮中输入的网址是:seeOtherLink /关于/和你正在使用.htaccass使网址用户友好。因此,您所在的页面有以下链接:bolade/1/。所以当你点击这个页面上的链接时,它会简单地将它添加到当前的URL中,所以新的URL将是:bolade/1/ + seeOtherLink/About/ = bolade/1/seeOtherLink/About/这不是一个页面,也不是一个路径。所以服务器会给你一个错误。

您必须更改网址:seeOtherLink /关于/到:http://website/seeOtherLink/About/和ofcourse,还必须将其添加到您的的.htaccess文件

希望这将帮助你


更新

所以我的理解是,所有的文件位于下BD文件夹的index.php有2个环节,这两个点beedy.php,然后beedy.php有2个链接指向about.phpcontact.php

所以你。htaccess文件应该类似于下面:

Options +FollowSymLinks 
Options All -Indexes 
RewriteEngine On 
# ------------------------------------------- 

RewriteRule ^home      index.php  [L,NC] 
RewriteRule ^About      about.php  [L,NC] 
RewriteRule ^Contact      contact.php  [L,NC] 
RewriteRule ^bolade/([a-zA-Z0-9-]+)$  beedy.php?user=$1&%{QUERY_STRING} [L,NC] 
RewriteRule ^bolade      beedy.php  [L,NC] 

# ------------------------------------------- 
RewriteCond %{REQUEST_URI} !^/(.*) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 

ErrorDocument 404 /404.html 

最终

我创建了一个项目,并尝试你的榜样,它在我的机器上的完美。请仔细遵循以下步骤:

第1步: 创建一个名为新项目:在根文件夹计算器

步骤2: 创建的index.php文件与以下代码:

<html> 
<head> <title>Hey</title></head> 
<body> 
<h1 > THIS IS HOME PAGE </h1> 
<a href="bolade/1"> Link 1 </a> 
<br /> 
<a href="bolade/2">Link 2</a> 

</body> 
</html> 

步骤3: 创建beedy.php文件与以下代码:

<?php 
    $id = $_GET["user"] ; 

    switch ($id) { 
     case 1: 
      echo "This is the First value<br />" ; 
      break ; 

     case 2: 
      echo "This is the Second value<br />" ; 
      break ; 
    } 
?> 

<html> 
    <head><title>Hey Beedy</title></head> 
    <body> 
     <a href="/stackoverflow/about"> Go to About Us</a> 
     <br /> 
     <a href="/stackoverflow/contact"> Go to Contact Us</a> 
     <br /> 
    </body> 
</html> 

请注意,链接指向完整的网址星婷从根文件

第4步: 创建about.php & contact.php文件。

第5步: 与下面的代码创建.htaccess文件:

Options +FollowSymLinks 
Options All -Indexes 
RewriteEngine On 
# ------------------------------------------- 

RewriteRule ^home      index.php  [L,NC] 
RewriteRule ^about      about.php  [L,NC] 
RewriteRule ^contact      contact.php  [L,NC] 
RewriteRule ^bolade/([a-zA-Z0-9-]+)$  beedy.php?user=$1&%{QUERY_STRING} [L,NC] 
RewriteRule ^bolade      beedy.php  [L,NC] 

# ------------------------------------------- 
RewriteCond %{REQUEST_URI} !^/(.*) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 

ErrorDocument 404 /404.html 

如果您仍然有问题,我可以给你我创建的测试项目。

+0

谢谢。请你给我一个例子,说明如何在我的.htaccess文件中调整它 –

+0

当然是的,但首先请你将项目结构发送给我,文件位于哪里?他们在同一个目录吗? –

+0

好的,谢谢...父文件夹的名称是'mvc',里面有一个名为'bd'的子文件夹,是我的htaccess文件和索引以及关于我们的地方。但我在mvc里面也有一些文件。所以它就像这样Mvc-> bd-> htaccess,beedy.php,index.PHP和about.php –