[英]Hide Part of URL htaccess
The Goal: 目标:
The user clicks on the title of one article using this href
link in a table: 用户使用表中的以下href
链接单击一篇文章的标题:
<a href='"."article.php/".$type."/".$id."/".$web_title."'>".$title."</a>
$type
get directed to article.php
. 来自任何$type
所有链接都定向到article.php
。 article.php
should be built dynamically based on the $id
retrieving information from the database. 应该基于从数据库检索信息的$id
动态构建article.php
。 I've got this URL rewrite in my htaccess file: 我在htaccess文件中重写了该URL:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/article/?
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-l
RewriteRule ^(.*)$ article.php?post_type=$1&post_id=$2&post_name=$3 [QSA,L]
Which is producing the URL: http://example.org/article.php/news/1/first-article-test
when the user accesses article.php
via a link described in point 2. 当用户通过第2点中描述的链接访问article.php
时, article.php
生成URL: http://example.org/article.php/news/1/first-article-test
: http://example.org/article.php/news/1/first-article-test
。
I'm trying to remove the article.php
section from the above URL, so it looks just like this: http://example.org/news/1/first-article-test
我正在尝试从上述URL中删除article.php
部分,因此它看起来像这样: http://example.org/news/1/first-article-test
: http://example.org/news/1/first-article-test
At the moment the article.php
page is receiving the variables just fine, it's pulling down other data from the database based on the $id
passed by the link, but the URL is displaying article.php/...
. 目前article.php
页面正好接收到变量,它正在根据链接传递的$id
从数据库中提取其他数据,但是URL显示的是article.php/...
Keep your rule like this: 保持规则如下:
RewriteEngine On
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-l
RewriteCond %{REQUEST_URI} !^/article\.php [NC]
RewriteRule ^(.+)$ /article.php/$1 [L]
It will let you have your links as 它将使您的链接成为
http://example.org/news/1/first-article-test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.