URL以动态的URL在PHP重写 [英] Url Rewriting with Dynamic URL's in PHP

查看:287
本文介绍了URL以动态的URL在PHP重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了一些URL重写堆栈上的问题和有关了实施该被张贴的解决方案,但我不能得到它的工作。我使用的动态URL的职位。因此,每个帖子都有一个ID和原始地址如下:本地主机/ post.php中= ID ?。我目前想获得刚本地主机/后/ ID

下面是的.htaccess的一个片段:

 选项+了FollowSymLinks
IndexIgnore * / *
RewriteEngine叙述上

的RewriteBase /


重写规则^ /后/([0-9] +)/ $ /post.php?=$1 [L]


的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。 routing.php
 

解决方案

尝试:

 重写规则^交/([0-9] +)?$ post.php中?ID = $ 1
 

您必须编写你的链接:< A HREF =?交/< = $ ID;>中>< = $标题;>< / A&GT? ;

和文件post.php中

 回声$ _GET ['身份证'];
 

I've already looked at some URL rewriting questions on stack and gone about implementing the solutions that were posted but I can't get it to work. I am using dynamic URL's for posts. So, each post has an id and the original url looks like: localhost/post.php?=id. I currently am trying to get just localhost/post/id.

Here is a snippet of the .htaccess:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On

RewriteBase /


RewriteRule ^/post/([0-9]+)/?$ /post.php?=$1 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . routing.php

解决方案

Try:

RewriteRule ^post/([0-9]+)?$ post.php?id=$1

You must write your link: <a href="post/<?=$id;?>"><?=$title;?></a>

And file post.php

echo $_GET['id'];

这篇关于URL以动态的URL在PHP重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆