【发布时间】:2015-07-31 05:59:06
【问题描述】:
这是我的 php 代码(qs.php)。该文件包含漂亮的 url 链接。
<html>
<head></head>
<body>
<?php
$file = 'qs1'; //this is a php file qs1.php
$id = '12345678'; //testing ID
$complete_url = $file."/".$id;
?>
<a href ="<?php echo $complete_url;?>"> This is a test link </a>
</body></html>
此链接出现链接此-http://localhost/qs1/12345678
QS1 是一个 php 文件 (qs1.php)。
以下是目前的 htaccess 文件。
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $qs1.php?var1=$2 [NC,L]
在 qs1.php 文件中,我通过 $_GET['var1'] 获取查询字符串 var1
我希望可以通过此 url http://localhost/qs1/12345678 访问链接。
如果用户像这样http://localhost/qs1/12345678/在末尾加上斜线,那么页面会将自己重定向到这个http://localhost/qs1/12345678。
目前我在打开此 http://localhost/qs1/12345678/ 时收到错误 404
感谢您的评论。
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect